Permalink
Browse files

Replaced dispatch_once with @synchronised() in SINGLETON

  • Loading branch information...
1 parent 64e112f commit 6ee1724de123d2eb2cde37c86c60beb889b09a14 Alen Zhou committed Jul 31, 2012
Showing with 10 additions and 4 deletions.
  1. +5 −2 Classes/SBJsonStreamParserState.m
  2. +5 −2 Classes/SBJsonStreamWriterState.m
View
7 Classes/SBJsonStreamParserState.m
@@ -36,8 +36,11 @@
#define SINGLETON \
+ (id)sharedInstance { \
static id state = nil; \
- static dispatch_once_t once = 0; \
- dispatch_once(&once, ^{state = [[self alloc] init];}); \
+ if (!state) { \
+ @synchronized(self) { \
+ if (!state) state = [[self alloc] init]; \
+ } \
+ } \
return state; \
}
View
7 Classes/SBJsonStreamWriterState.m
@@ -36,8 +36,11 @@
#define SINGLETON \
+ (id)sharedInstance { \
static id state = nil; \
- static dispatch_once_t once = 0; \
- dispatch_once(&once, ^{state = [[self alloc] init];}); \
+ if (!state) { \
+ @synchronized(self) { \
+ if (!state) state = [[self alloc] init]; \
+ } \
+ } \
return state; \
}

0 comments on commit 6ee1724

Please sign in to comment.