diff options
Diffstat (limited to 'src/lib/icu/Converter.hxx')
-rw-r--r-- | src/lib/icu/Converter.hxx | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/lib/icu/Converter.hxx b/src/lib/icu/Converter.hxx index f20dc6f7c..26eccfe94 100644 --- a/src/lib/icu/Converter.hxx +++ b/src/lib/icu/Converter.hxx @@ -23,7 +23,10 @@ #include "check.h" #include "Compiler.h" -#ifdef HAVE_GLIB +#ifdef HAVE_ICU +#include "thread/Mutex.hxx" +#define HAVE_ICU_CONVERTER +#elif defined(HAVE_GLIB) #include <glib.h> #define HAVE_ICU_CONVERTER #endif @@ -34,21 +37,41 @@ class Error; +#ifdef HAVE_ICU +struct UConverter; +#endif + /** * This class can convert strings with a certain character set to and * from UTF-8. */ class IcuConverter { +#ifdef HAVE_ICU + /** + * ICU's UConverter class is not thread-safe. This mutex + * serializes simultaneous calls. + */ + mutable Mutex mutex; + + UConverter *const converter; + + IcuConverter(UConverter *_converter):converter(_converter) {} +#elif defined(HAVE_GLIB) const GIConv to_utf8, from_utf8; IcuConverter(GIConv _to, GIConv _from) :to_utf8(_to), from_utf8(_from) {} +#endif public: +#ifdef HAVE_ICU + ~IcuConverter(); +#elif defined(HAVE_GLIB) ~IcuConverter() { g_iconv_close(to_utf8); g_iconv_close(from_utf8); } +#endif static IcuConverter *Create(const char *charset, Error &error); |