[vlc-devel] [PATCH 07/13] VLCKit: migrate VLCMediaLibrary to ARC
Florent Pillet
fpillet at gmail.com
Mon Jul 7 12:41:22 CEST 2014
with enhanced thread safety
---
Headers/Public/VLCMediaLibrary.h | 5 +++--
Sources/VLCMediaLibrary.m | 35 +++++++++++++++++++----------------
2 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/Headers/Public/VLCMediaLibrary.h b/Headers/Public/VLCMediaLibrary.h
index e98d370..1efcd36 100644
--- a/Headers/Public/VLCMediaLibrary.h
+++ b/Headers/Public/VLCMediaLibrary.h
@@ -32,11 +32,12 @@
@interface VLCMediaLibrary : NSObject
{
void * mlib;
- VLCMediaList * allMedia;
}
+
/* Factories */
+ (id)sharedMediaLibrary;
/* Properties */
- at property (readonly) VLCMediaList * allMedia;
+ at property (nonatomic, readonly, strong) VLCMediaList * allMedia;
+
@end
diff --git a/Sources/VLCMediaLibrary.m b/Sources/VLCMediaLibrary.m
index d450abd..87e38f1 100644
--- a/Sources/VLCMediaLibrary.m
+++ b/Sources/VLCMediaLibrary.m
@@ -29,15 +29,25 @@
#include <vlc/libvlc.h>
+ at interface VLCMediaLibrary ()
+
+ at property (nonatomic) dispatch_once_t once;
+ at property (nonatomic, readwrite, strong) VLCMediaList * allMedia;
+
+ at end
+
@implementation VLCMediaLibrary
+
+ (id)sharedMediaLibrary
{
static VLCMediaLibrary * sharedMediaLibrary = nil;
- if( !sharedMediaLibrary )
- {
+ static dispatch_once_t onceToken;
+
+ dispatch_once(&onceToken, ^{
sharedMediaLibrary = [[VLCMediaLibrary alloc] init];
- }
- return sharedMediaLibrary;
+ });
+
+ return sharedMediaLibrary;
}
- (id)init
@@ -45,32 +55,25 @@
if (self = [super init])
{
mlib = libvlc_media_library_new( [VLCLibrary sharedInstance]);
-
libvlc_media_library_load( mlib );
-
- allMedia = nil;
}
return self;
}
- (void)dealloc
{
- [allMedia release];
-
libvlc_media_library_release(mlib);
mlib = nil; // make sure that the pointer is dead
-
- [super dealloc];
}
- (VLCMediaList *)allMedia
{
- if( !allMedia )
- {
+ dispatch_once(&_once, ^{
libvlc_media_list_t * p_mlist = libvlc_media_library_media_list( mlib );
- allMedia = [[VLCMediaList mediaListWithLibVLCMediaList:p_mlist] retain];
+ _allMedia = [VLCMediaList mediaListWithLibVLCMediaList:p_mlist];
libvlc_media_list_release(p_mlist);
- }
- return allMedia;
+ });
+ return _allMedia;
}
+
@end
--
1.8.5.2 (Apple Git-48)
More information about the vlc-devel
mailing list