Use TLS and converter manager in locale backend.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#ifndef _ICU_CATEGORY_DATA_H
|
||||
#define _ICU_CATEGORY_DATA_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <unicode/locid.h>
|
||||
#include <unicode/ucnv.h>
|
||||
@@ -12,6 +13,8 @@
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include "ICUConverterManager.h"
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Libroot {
|
||||
@@ -19,14 +22,14 @@ namespace Libroot {
|
||||
|
||||
class ICUCategoryData {
|
||||
public:
|
||||
ICUCategoryData();
|
||||
ICUCategoryData(pthread_key_t tlsKey);
|
||||
virtual ~ICUCategoryData();
|
||||
|
||||
virtual status_t SetTo(const Locale& locale,
|
||||
const char* posixLocaleName);
|
||||
virtual status_t SetToPosix();
|
||||
|
||||
const char * PosixLocaleName()
|
||||
const char* PosixLocaleName()
|
||||
{ return fPosixLocaleName; }
|
||||
|
||||
protected:
|
||||
@@ -35,16 +38,18 @@ protected:
|
||||
char* destination, int destinationSize,
|
||||
const char* defaultValue = "");
|
||||
|
||||
status_t _GetConverter(ICUConverterRef& converterRefOut);
|
||||
|
||||
static const uint16 skMaxPosixLocaleNameLen = 128;
|
||||
static const size_t skLCBufSize = 16;
|
||||
|
||||
pthread_key_t fThreadLocalStorageKey;
|
||||
Locale fLocale;
|
||||
UConverter* fConverter;
|
||||
char fPosixLocaleName[skMaxPosixLocaleNameLen];
|
||||
char fGivenCharset[UCNV_MAX_CONVERTER_NAME_LENGTH];
|
||||
|
||||
private:
|
||||
status_t _SetupConverter();
|
||||
status_t _SetupConverter();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class ICUCollateData : public ICUCategoryData {
|
||||
typedef ICUCategoryData inherited;
|
||||
|
||||
public:
|
||||
ICUCollateData();
|
||||
ICUCollateData(pthread_key_t tlsKey);
|
||||
virtual ~ICUCollateData();
|
||||
|
||||
virtual status_t SetTo(const Locale& locale,
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Libroot {
|
||||
class ICUCtypeData : public ICUCategoryData {
|
||||
typedef ICUCategoryData inherited;
|
||||
public:
|
||||
ICUCtypeData();
|
||||
ICUCtypeData(pthread_key_t tlsKey);
|
||||
virtual ~ICUCtypeData();
|
||||
|
||||
void Initialize(LocaleCtypeDataBridge* dataBridge);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "LocaleBackend.h"
|
||||
|
||||
#include <locale.h>
|
||||
#include <pthread.h>
|
||||
#include <timelocal.h>
|
||||
|
||||
#include "ICUCollateData.h"
|
||||
@@ -57,6 +58,9 @@ private:
|
||||
const char* _QueryLocale(int category);
|
||||
const char* _SetPosixLocale(int category);
|
||||
|
||||
static pthread_key_t _CreateThreadLocalStorageKey();
|
||||
static void _DestroyThreadLocalStorageValue(void* value);
|
||||
|
||||
// buffer for locale names (up to one per category)
|
||||
char fLocaleDescription[512];
|
||||
|
||||
@@ -64,6 +68,9 @@ private:
|
||||
struct lconv fLocaleConv;
|
||||
struct lc_time_t fLCTimeInfo;
|
||||
|
||||
//
|
||||
pthread_key_t fThreadLocalStorageKey;
|
||||
|
||||
// these work on the data containers above
|
||||
ICUCollateData fCollateData;
|
||||
ICUCtypeData fCtypeData;
|
||||
|
||||
@@ -21,6 +21,8 @@ class ICULocaleconvData : public ICUCategoryData {
|
||||
typedef ICUCategoryData inherited;
|
||||
|
||||
protected:
|
||||
ICULocaleconvData(pthread_key_t tlsKey);
|
||||
|
||||
status_t _SetLocaleconvEntry(
|
||||
const DecimalFormatSymbols* formatSymbols,
|
||||
char* destination, FormatSymbol symbol,
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace Libroot {
|
||||
|
||||
class ICUMessagesData : public ICUCategoryData {
|
||||
typedef ICUCategoryData inherited;
|
||||
|
||||
public:
|
||||
ICUMessagesData(pthread_key_t tlsKey);
|
||||
|
||||
virtual status_t SetTo(const Locale& locale,
|
||||
const char* posixLocaleName);
|
||||
virtual status_t SetToPosix();
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace Libroot {
|
||||
|
||||
class ICUMonetaryData : public ICULocaleconvData {
|
||||
typedef ICULocaleconvData inherited;
|
||||
|
||||
public:
|
||||
static const int32 kParenthesesAroundCurrencyAndValue = 0;
|
||||
static const int32 kSignPrecedesCurrencyAndValue = 1;
|
||||
@@ -25,7 +26,8 @@ public:
|
||||
static const int32 kSignImmediatelyPrecedesCurrency = 3;
|
||||
static const int32 kSignImmediatelySucceedsCurrency = 4;
|
||||
|
||||
ICUMonetaryData(struct lconv& localeConv);
|
||||
ICUMonetaryData(pthread_key_t tlsKey,
|
||||
struct lconv& localeConv);
|
||||
|
||||
void Initialize(
|
||||
LocaleMonetaryDataBridge* dataBridge);
|
||||
|
||||
@@ -18,7 +18,8 @@ class ICUNumericData : public ICULocaleconvData {
|
||||
typedef ICULocaleconvData inherited;
|
||||
|
||||
public:
|
||||
ICUNumericData(struct lconv& localeConv);
|
||||
ICUNumericData(pthread_key_t tlsKey,
|
||||
struct lconv& localeConv);
|
||||
|
||||
void Initialize(LocaleNumericDataBridge* dataBridge);
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ namespace Libroot {
|
||||
class ICUTimeData : public ICUCategoryData {
|
||||
typedef ICUCategoryData inherited;
|
||||
public:
|
||||
ICUTimeData(struct lc_time_t& lcTimeInfo);
|
||||
ICUTimeData(pthread_key_t tlsKey,
|
||||
struct lc_time_t& lcTimeInfo);
|
||||
~ICUTimeData();
|
||||
|
||||
void Initialize(LocaleTimeDataBridge* dataBridge);
|
||||
|
||||
Reference in New Issue
Block a user