Re: Changing head item on a (GCD) Queue


Dave
 

Hi,

I get it now, in this case the predicate is actually the (protected) Array, I’ve changed it yet again it just process one item at time. I’ll test it tomorrow and then add higher level code to make use of it and then add support for processing the queue and removing useless items.

Cheers
Dave

-(instancetype) init
{
self = [super init];
if (self == nil)
return nil;

self.pProcessingQueue = [[LTWQueue alloc] init];
self.pConsumerTaskWakeUpCondition = [[NSCondition alloc] init];
self.pLastQueueCount = 0;

[NSThread detachNewThreadSelector:@selector(consumerTask) toTarget:self withObject:nil];

return self;
}



-(void) processObject:(id) theObject
{
}



-(void) consumerTask
{
while (YES)
{
[self.pConsumerTaskWakeUpCondition lock];
[self.pConsumerTaskWakeUpCondition wait];

self.pLastObjectRemoved = [self.pProcessingQueue queueGetHead];
if (self.pLastObjectRemoved != nil)
[self processObject:self.pLastObjectRemoved];

[self.pConsumerTaskWakeUpCondition unlock];
}
}



-(void) addObject:(id) theObject
{
[self.pConsumerTaskWakeUpCondition lock];
[self.pProcessingQueue queuePutTail:theObject];

[self.pConsumerTaskWakeUpCondition signal];
[self.pConsumerTaskWakeUpCondition unlock];
}

Join cocoa@apple-dev.groups.io to automatically receive all group messages.