|
@@ -11,7 +11,6 @@
|
|
|
|
|
|
#import "YYClassInfo.h"
|
|
#import "YYClassInfo.h"
|
|
#import <objc/runtime.h>
|
|
#import <objc/runtime.h>
|
|
-#import <libkern/OSAtomic.h>
|
|
|
|
|
|
|
|
YYEncodingType YYEncodingGetType(const char *typeEncoding) {
|
|
YYEncodingType YYEncodingGetType(const char *typeEncoding) {
|
|
char *type = (char *)typeEncoding;
|
|
char *type = (char *)typeEncoding;
|
|
@@ -309,24 +308,24 @@ YYEncodingType YYEncodingGetType(const char *typeEncoding) {
|
|
static CFMutableDictionaryRef classCache;
|
|
static CFMutableDictionaryRef classCache;
|
|
static CFMutableDictionaryRef metaCache;
|
|
static CFMutableDictionaryRef metaCache;
|
|
static dispatch_once_t onceToken;
|
|
static dispatch_once_t onceToken;
|
|
- static OSSpinLock lock;
|
|
|
|
|
|
+ static dispatch_semaphore_t lock;
|
|
dispatch_once(&onceToken, ^{
|
|
dispatch_once(&onceToken, ^{
|
|
classCache = CFDictionaryCreateMutable(CFAllocatorGetDefault(), 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
|
|
classCache = CFDictionaryCreateMutable(CFAllocatorGetDefault(), 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
|
|
metaCache = CFDictionaryCreateMutable(CFAllocatorGetDefault(), 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
|
|
metaCache = CFDictionaryCreateMutable(CFAllocatorGetDefault(), 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
|
|
- lock = OS_SPINLOCK_INIT;
|
|
|
|
|
|
+ lock = dispatch_semaphore_create(1);
|
|
});
|
|
});
|
|
- OSSpinLockLock(&lock);
|
|
|
|
|
|
+ dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
|
YYClassInfo *info = CFDictionaryGetValue(class_isMetaClass(cls) ? metaCache : classCache, (__bridge const void *)(cls));
|
|
YYClassInfo *info = CFDictionaryGetValue(class_isMetaClass(cls) ? metaCache : classCache, (__bridge const void *)(cls));
|
|
if (info && info->_needUpdate) {
|
|
if (info && info->_needUpdate) {
|
|
[info _update];
|
|
[info _update];
|
|
}
|
|
}
|
|
- OSSpinLockUnlock(&lock);
|
|
|
|
|
|
+ dispatch_semaphore_signal(lock);
|
|
if (!info) {
|
|
if (!info) {
|
|
info = [[YYClassInfo alloc] initWithClass:cls];
|
|
info = [[YYClassInfo alloc] initWithClass:cls];
|
|
if (info) {
|
|
if (info) {
|
|
- OSSpinLockLock(&lock);
|
|
|
|
|
|
+ dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
|
CFDictionarySetValue(info.isMeta ? metaCache : classCache, (__bridge const void *)(cls), (__bridge const void *)(info));
|
|
CFDictionarySetValue(info.isMeta ? metaCache : classCache, (__bridge const void *)(cls), (__bridge const void *)(info));
|
|
- OSSpinLockUnlock(&lock);
|
|
|
|
|
|
+ dispatch_semaphore_signal(lock);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return info;
|
|
return info;
|