Remove the useless init method from MP42Fifo interface and be safer in the implementation

This commit is contained in:
galad87 committed 2015-08-29 11:40:37 +02:00
1 parent fa39cf9f4b
commit b70e19961c
2 files changed
+8 -9

No files matched your search

+1 -2
View File
@@ -26,8 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
dispatch_semaphore_t _empty;
}
- (instancetype)init;
- (instancetype)initWithCapacity:(NSUInteger)numItems NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithCapacity:(NSUInteger)capacity NS_DESIGNATED_INITIALIZER;
- (void)enqueue:(ObjectType)item;
- (nullable ObjectType)deque NS_RETURNS_RETAINED;
+7 -7
View File
@@ -15,10 +15,10 @@
return self;
}
- (instancetype)initWithCapacity:(NSUInteger)numItems {
- (instancetype)initWithCapacity:(NSUInteger)capacity {
self = [super init];
if (self) {
_size = (int32_t)numItems;
_size = (int32_t)capacity;
_array = (id *) malloc(sizeof(id) * _size);
_full = dispatch_semaphore_create(_size - 1);
_empty = dispatch_semaphore_create(0);
@@ -40,11 +40,11 @@
_tail = 0;
}
OSAtomicIncrement32(&_count);
OSAtomicIncrement32Barrier(&_count);
dispatch_semaphore_signal(_empty);
}
- (id)deque {
- (nullable id)deque {
if (!_count) return nil;
id item = _array[_head++];
@@ -53,17 +53,17 @@
_head = 0;
}
OSAtomicDecrement32(&_count);
OSAtomicDecrement32Barrier(&_count);
dispatch_semaphore_signal(_full);
return item;
}
- (id)dequeAndWait {
- (nullable id)dequeAndWait {
id item = [self deque];
if (!item) {
dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC/1000);
dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC / 1000);
dispatch_semaphore_wait(_empty, time);
}