Skip to content

Commit

Permalink
Merge pull request #140 from AlenZhou/master
Browse files Browse the repository at this point in the history
Make SINGLETON thread safe
  • Loading branch information
stig committed Jul 31, 2012
2 parents cbdf88a + 6ee1724 commit 8e0d32c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Classes/SBJsonStreamParserState.m
Expand Up @@ -36,7 +36,11 @@
#define SINGLETON \
+ (id)sharedInstance { \
static id state = nil; \
if (!state) state = [[self alloc] init]; \
if (!state) { \
@synchronized(self) { \
if (!state) state = [[self alloc] init]; \
} \
} \
return state; \
}

Expand Down
8 changes: 6 additions & 2 deletions Classes/SBJsonStreamWriterState.m
Expand Up @@ -35,8 +35,12 @@

#define SINGLETON \
+ (id)sharedInstance { \
static id state; \
if (!state) state = [[self alloc] init]; \
static id state = nil; \
if (!state) { \
@synchronized(self) { \
if (!state) state = [[self alloc] init]; \
} \
} \
return state; \
}

Expand Down

0 comments on commit 8e0d32c

Please sign in to comment.