2005-09-07 22:33:16 +00:00
|
|
|
//
|
|
|
|
// Semaphore.m
|
|
|
|
// Cog
|
|
|
|
//
|
2006-09-04 18:46:18 +00:00
|
|
|
// Created by Vincent Spader on 8/2/05.
|
|
|
|
// Copyright 2005 Vincent Spader. All rights reserved.
|
2005-09-07 22:33:16 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "Semaphore.h"
|
|
|
|
|
|
|
|
|
|
|
|
@implementation Semaphore
|
|
|
|
|
|
|
|
-(id)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
semaphore_create(mach_task_self(), &semaphore, SYNC_POLICY_FIFO, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)signal
|
|
|
|
{
|
2006-01-20 15:34:02 +00:00
|
|
|
semaphore_signal_all(semaphore);
|
2005-09-07 22:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-(void)timedWait:(int)seconds
|
|
|
|
{
|
|
|
|
mach_timespec_t timeout = {seconds, 0};
|
|
|
|
|
|
|
|
semaphore_timedwait(semaphore, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)wait
|
|
|
|
{
|
2006-01-20 15:34:02 +00:00
|
|
|
mach_timespec_t t = {2.0, 0.0}; //2 second timeout
|
|
|
|
semaphore_timedwait(semaphore, t);
|
2005-09-07 22:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|