]> git.saurik.com Git - apple/libc.git/blobdiff - locale/xlocale_private.h
Libc-1272.200.26.tar.gz
[apple/libc.git] / locale / xlocale_private.h
index d08328c1a8ac5bf82a438bbba152de8cb783ba64..94f8ecc526931317dfe73e0b8567823247c40332 100644 (file)
@@ -32,8 +32,9 @@
 #include <locale.h>
 #include <libkern/OSAtomic.h>
 #include <pthread.h>
-#include <pthread_spinlock.h>
+#include <pthread/tsd_private.h>
 #include <limits.h>
+#include <os/lock.h>
 #include "setlocale.h"
 #include "collate.h"
 #include "runetype.h"
 #include "lmonetary.h"
 #include "lnumeric.h"
 #include "timelocal.h"
+#include <TargetConditionals.h>
 
 #undef MB_CUR_MAX
 #define MB_CUR_MAX     (__current_locale()->__lc_ctype->__mb_cur_max)
 #undef MB_CUR_MAX_L
 #define MB_CUR_MAX_L(x)        ((x)->__lc_ctype->__mb_cur_max)
 
-extern int __is_threaded;
-
 typedef void (*__free_extra_t)(void *);
 
 #define XPERMANENT     ((__free_extra_t)-1)
@@ -71,6 +71,7 @@ struct __xlocale_st_runelocale {
        __STRUCT_COMMON
        char __ctype_encoding[ENCODING_LEN + 1];
        int __mb_cur_max;
+       int __mb_sb_limit;
        size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict,
            size_t, __darwin_mbstate_t * __restrict, struct _xlocale *);
        int (*__mbsinit)(const __darwin_mbstate_t *, struct _xlocale *);
@@ -132,7 +133,7 @@ struct _xlocale {
        __darwin_mbstate_t __mbs_wcsnrtombs;
        __darwin_mbstate_t __mbs_wcsrtombs;
        __darwin_mbstate_t __mbs_wctomb;
-       pthread_lock_t __lock;
+       os_unfair_lock __lock;
 /* magic (Here up to the end is copied when duplicating locale_t's) */
        int64_t __magic;
 /* flags */
@@ -162,24 +163,37 @@ struct _xlocale {
        struct lconv __lc_localeconv;
 };
 
+#define DEFAULT_CURRENT_LOCALE(x)      \
+                               if ((x) == NULL) { \
+                                       (x) = __current_locale(); \
+                               } else if ((x) == LC_GLOBAL_LOCALE) { \
+                                       (x) = &__global_locale; \
+                               }
+
 #define NORMALIZE_LOCALE(x)    if ((x) == NULL) { \
                                        (x) = _c_locale; \
                                } else if ((x) == LC_GLOBAL_LOCALE) { \
                                        (x) = &__global_locale; \
                                }
 
-#define XL_LOCK(x)     LOCK((x)->__lock);
+#define XL_LOCK(x)     os_unfair_lock_lock(&(x)->__lock);
 #define        XL_RELEASE(x)   if ((x) && (x)->__free_extra != XPERMANENT && OSAtomicDecrement32Barrier(&(x)->__refcount) == 0) { \
                                if ((x)->__free_extra) \
                                        (*(x)->__free_extra)((x)); \
                                free((x)); \
+                               (x) = NULL; \
                        }
 #define        XL_RETAIN(x)    if ((x) && (x)->__free_extra != XPERMANENT) { OSAtomicIncrement32Barrier(&(x)->__refcount); }
-#define XL_UNLOCK(x)   UNLOCK((x)->__lock);
+#define XL_UNLOCK(x)   os_unfair_lock_unlock(&(x)->__lock);
+
+__attribute__((visibility("hidden")))
+extern struct __xlocale_st_runelocale _DefaultRuneXLocale;
+
+__attribute__((visibility("hidden")))
+extern struct _xlocale __global_locale;
 
-__private_extern__ struct __xlocale_st_runelocale _DefaultRuneXLocale;
-__private_extern__ struct _xlocale     __global_locale;
-__private_extern__ pthread_key_t       __locale_key;
+__attribute__((visibility("hidden")))
+extern pthread_key_t   __locale_key;
 
 __BEGIN_DECLS
 
@@ -190,8 +204,21 @@ void       __xlocale_init(void);
 static inline __attribute__((always_inline)) locale_t
 __current_locale(void)
 {
-       locale_t __locale = (locale_t)pthread_getspecific(__locale_key);
-       return (__locale ? __locale : &__global_locale);
+#if TARGET_IPHONE_SIMULATOR
+       /* <rdar://problem/14136256> Crash in _objc_inform for duplicate class name during simulator launch
+        * TODO: Remove after the simulator's libSystem is initialized properly.
+        */
+       if (__locale_key == (pthread_key_t)-1) {
+               return &__global_locale;
+       }
+#endif
+       void *__thread_locale;
+       if (_pthread_has_direct_tsd()) {
+               __thread_locale = _pthread_getspecific_direct(__locale_key);
+       } else {
+               __thread_locale = pthread_getspecific(__locale_key);
+       }
+       return (__thread_locale ? (locale_t)__thread_locale : &__global_locale);
 }
 
 static inline __attribute__((always_inline)) locale_t