Guest User

Untitled

a guest
Jan 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1.  
  2. + (id)defaultCenter
  3. {
  4. static MAKVONotificationCenter *center = nil;
  5. if(!center)
  6. {
  7. // do a bit of clever atomic setting to make this thread safe
  8. // if two threads try to set simultaneously, one will fail
  9. // and the other will set things up so that the failing thread
  10. // gets the shared center
  11. MAKVONotificationCenter *newCenter = [[self alloc] init];
  12. if(!OSAtomicCompareAndSwapPtrBarrier(nil, newCenter, (void *)&center))
  13. [newCenter release];
  14. }
  15. return center;
  16. }
Add Comment
Please, Sign In to add comment