Browse Source

VLCEventManager: synchronize creation of shared object

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
Gleb Pinigin 12 years ago
parent
commit
86741aaff1
1 changed files with 5 additions and 4 deletions
  1. 5 4
      Sources/VLCEventManager.m

+ 5 - 4
Sources/VLCEventManager.m

@@ -166,11 +166,12 @@ static void * EventDispatcherMainLoop(void * user_data)
 @implementation VLCEventManager
 + (id)sharedManager
 {
-    static VLCEventManager *defaultManager = NULL;
+    static VLCEventManager *defaultManager = nil;
 
-    /* We do want a lock here to avoid leaks */
-    if (!defaultManager)
-        defaultManager = [[VLCEventManager alloc] init];
+    if (defaultManager == nil)
+        @synchronized([VLCEventManager class]) {
+            defaultManager = [[VLCEventManager alloc] init];
+        }
 
     return defaultManager;
 }