This magically fixes the stupid header maps that were pulling the system semaphore.h into Swift projects, when they shouldn't have been doing that in the first place. This is the same reason that the FLAC library has its assert.h renamed to FLAC_assert.h. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
41 lines
702 B
Objective-C
41 lines
702 B
Objective-C
//
|
|
// CogSemaphore.m
|
|
// Cog
|
|
//
|
|
// Created by Vincent Spader on 8/2/05.
|
|
// Copyright 2005 Vincent Spader. All rights reserved.
|
|
//
|
|
|
|
#import <CogAudio/CogSemaphore.h>
|
|
|
|
@implementation Semaphore
|
|
|
|
- (id)init {
|
|
self = [super init];
|
|
if(self) {
|
|
semaphore_create(mach_task_self(), &semaphore, SYNC_POLICY_FIFO, 0);
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void)signal {
|
|
semaphore_signal_all(semaphore);
|
|
}
|
|
|
|
- (void)timedWait:(int)microseconds {
|
|
mach_timespec_t timeout = { 0, microseconds * 1000UL };
|
|
|
|
semaphore_timedwait(semaphore, timeout);
|
|
}
|
|
|
|
- (void)wait {
|
|
mach_timespec_t t = { 2.0, 0.0 }; // 2 second timeout
|
|
semaphore_timedwait(semaphore, t);
|
|
}
|
|
|
|
- (void)waitIndefinitely {
|
|
semaphore_wait(semaphore);
|
|
}
|
|
|
|
@end
|