00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "loccache.h"
00021 #include "uhash.h"
00022 #include "unicode/uloc.h"
00023 #include "umutex.h"
00024
00025
00026 UHashtable *gLocaleCache = 0;
00027
00028 ULocaleBundle*
00029 u_loccache_get(const char *loc)
00030 {
00031 ULocaleBundle *result;
00032 ULocaleBundle *tempBundle;
00033
00034 UHashtable *tempCache;
00035 int32_t locCount;
00036 UErrorCode status = U_ZERO_ERROR;
00037
00038
00039 if(gLocaleCache == 0) {
00040 locCount = uloc_countAvailable();
00041
00042 tempCache = uhash_openSize(uhash_hashChars, uhash_compareChars, locCount, &status);
00043 if(U_FAILURE(status)) return 0;
00044
00045
00046 umtx_lock(0);
00047
00048 if(gLocaleCache == 0) {
00049 gLocaleCache = tempCache;
00050 }
00051 else {
00052 uhash_close(tempCache);
00053 }
00054
00055
00056 umtx_unlock(0);
00057 }
00058
00059
00060
00061
00062
00063
00064 result = (ULocaleBundle*)uhash_get(gLocaleCache, loc);
00065
00066
00067 if(result == 0) {
00068
00069 tempBundle = u_locbund_new(loc);
00070
00071
00072 umtx_lock(0);
00073
00074
00075 result = (ULocaleBundle*)uhash_get(gLocaleCache, loc);
00076 if(result == 0) {
00077 result = tempBundle;
00078 uhash_put(gLocaleCache, tempBundle->fLocale, tempBundle, &status);
00079 }
00080 else
00081 u_locbund_delete(tempBundle);
00082
00083
00084 umtx_unlock(0);
00085 }
00086
00087 return result;
00088 }