* Copyright (c) 2014 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
- *
+ *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
- *
+ *
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
- *
+ *
* @APPLE_LICENSE_HEADER_END@
*/
/* CFLocale.c
- Copyright (c) 2002-2013, Apple Inc. All rights reserved.
+ Copyright (c) 2002-2014, Apple Inc. All rights reserved.
Responsibility: David Smith
*/
static CFLocaleRef __CFLocaleSystem = NULL;
static CFMutableDictionaryRef __CFLocaleCache = NULL;
-static CFSpinLock_t __CFLocaleGlobalLock = CFSpinLockInit;
+static CFLock_t __CFLocaleGlobalLock = CFLockInit;
struct __CFLocale {
CFRuntimeBase _base;
CFMutableDictionaryRef _cache;
CFMutableDictionaryRef _overrides;
CFDictionaryRef _prefs;
- CFSpinLock_t _lock;
+ CFLock_t _lock;
Boolean _nullLocale;
};
CF_PRIVATE Boolean __CFLocaleGetNullLocale(struct __CFLocale *locale) {
+ CF_OBJC_FUNCDISPATCHV(CFLocaleGetTypeID(), Boolean, (NSLocale *)locale, _nullLocale);
return locale->_nullLocale;
}
CF_PRIVATE void __CFLocaleSetNullLocale(struct __CFLocale *locale) {
+ CF_OBJC_FUNCDISPATCHV(CFLocaleGetTypeID(), void, (NSLocale *)locale, _setNullLocale);
locale->_nullLocale = true;
}
}
CF_INLINE void __CFLocaleLockGlobal(void) {
- __CFSpinLock(&__CFLocaleGlobalLock);
+ __CFLock(&__CFLocaleGlobalLock);
}
CF_INLINE void __CFLocaleUnlockGlobal(void) {
- __CFSpinUnlock(&__CFLocaleGlobalLock);
+ __CFUnlock(&__CFLocaleGlobalLock);
}
CF_INLINE void __CFLocaleLock(CFLocaleRef locale) {
- __CFSpinLock(&((struct __CFLocale *)locale)->_lock);
+ __CFLock(&((struct __CFLocale *)locale)->_lock);
}
CF_INLINE void __CFLocaleUnlock(CFLocaleRef locale) {
- __CFSpinUnlock(&((struct __CFLocale *)locale)->_lock);
+ __CFUnlock(&((struct __CFLocale *)locale)->_lock);
}
__CFLocaleCopyDescription
};
-static void __CFLocaleInitialize(void) {
- CFIndex idx;
- __kCFLocaleTypeID = _CFRuntimeRegisterClass(&__CFLocaleClass);
- for (idx = 0; idx < __kCFLocaleKeyTableCount; idx++) {
- // table fixup to workaround compiler/language limitations
- __CFLocaleKeyTable[idx].key = *((CFStringRef *)__CFLocaleKeyTable[idx].key);
- if (NULL != __CFLocaleKeyTable[idx].context) {
- __CFLocaleKeyTable[idx].context = *((CFStringRef *)__CFLocaleKeyTable[idx].context);
- }
- }
-}
-
CFTypeID CFLocaleGetTypeID(void) {
- if (_kCFRuntimeNotATypeID == __kCFLocaleTypeID) __CFLocaleInitialize();
+ static dispatch_once_t initOnce;
+ dispatch_once(&initOnce, ^{
+ __kCFLocaleTypeID = _CFRuntimeRegisterClass(&__CFLocaleClass); // initOnce covered
+ for (CFIndex idx = 0; idx < __kCFLocaleKeyTableCount; idx++) {
+ // table fixup to workaround compiler/language limitations
+ __CFLocaleKeyTable[idx].key = *((CFStringRef *)__CFLocaleKeyTable[idx].key);
+ if (NULL != __CFLocaleKeyTable[idx].context) {
+ __CFLocaleKeyTable[idx].context = *((CFStringRef *)__CFLocaleKeyTable[idx].context);
+ }
+ }
+ });
return __kCFLocaleTypeID;
}
locale->_cache = CFDictionaryCreateMutable(kCFAllocatorSystemDefault, 0, NULL, &kCFTypeDictionaryValueCallBacks);
locale->_overrides = NULL;
locale->_prefs = prefs;
- locale->_lock = CFSpinLockInit;
+ locale->_lock = CFLockInit;
locale->_nullLocale = false;
if (useCache) {
locale->_cache = CFDictionaryCreateMutable(allocator, 0, NULL, &kCFTypeDictionaryValueCallBacks);
locale->_overrides = NULL;
locale->_prefs = NULL;
- locale->_lock = CFSpinLockInit;
+ locale->_lock = CFLockInit;
if (canCache) {
if (NULL == __CFLocaleCache) {
__CFLocaleCache = CFDictionaryCreateMutable(kCFAllocatorSystemDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
}
CFLocaleRef CFLocaleCreateCopy(CFAllocatorRef allocator, CFLocaleRef locale) {
+ CF_OBJC_FUNCDISPATCHV(CFLocaleGetTypeID(), CFLocaleRef, (NSLocale *)locale, copy);
return (CFLocaleRef)CFRetain(locale);
}
} else if (CFEqual(*cf, kCFCalendarIdentifierEthiopicAmeteAlem)) {
CFRelease(*cf);
*cf = CFRetain(kCFCalendarIdentifierEthiopicAmeteAlem);
- } else {
+ } else if (CFEqual(*cf, kCFCalendarIdentifierIslamicTabular)) {
+ CFRelease(*cf);
+ *cf = CFRetain(kCFCalendarIdentifierIslamicTabular);
+ } else if (CFEqual(*cf, kCFCalendarIdentifierIslamicUmmAlQura)) {
+ CFRelease(*cf);
+ *cf = CFRetain(kCFCalendarIdentifierIslamicUmmAlQura);
+ } else {
CFRelease(*cf);
*cf = NULL;
return false;