Browse Source

IOSAD-157 Share locking code

IOSAD-157
Dirk Zimmermann 3 years ago
parent
commit
1dbd83dd59
1 changed files with 19 additions and 12 deletions
  1. +19
    -12
      pEpObjCAdapter/PEPQueue.m

+ 19
- 12
pEpObjCAdapter/PEPQueue.m View File

@ -31,28 +31,35 @@
return self;
}
- (void)enqueue:(id)object
/// A block that gets called to modify the queue model.
typedef void (^queueOp)(NSMutableArray *queue);
/// Lock the queue and calls the given block.
/// @param block The block to invoke once the queue is locked.
- (void)lockQueueAndUpdateWithBlock:(queueOp)block
{
[_cond lock];
if (_queue) {
[_queue insertObject:object atIndex:0];
block(_queue);
}
[_cond signal];
[_cond unlock];
}
- (void)prequeue:(id)object
- (void)enqueue:(id)object
{
[_cond lock];
if (_queue) {
[_queue addObject:object];
}
[self lockQueueAndUpdateWithBlock:^(NSMutableArray *queue){
[queue insertObject:object atIndex:0];
}];
}
[_cond signal];
[_cond unlock];
- (void)prequeue:(id)object
{
[self lockQueueAndUpdateWithBlock:^(NSMutableArray *queue){
[queue addObject:object];
}];
}
- (id)timedDequeue:(time_t*)timeout


Loading…
Cancel
Save