#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)
__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 *);
__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 */
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
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