Files
Xaibatsu-Control-Panel/XIONControlPanel/Utilities/Semaphore.swift
Charles Magahern 56de300889 iPhone Support
2016-07-24 00:14:04 -07:00

40 lines
745 B
Swift

//
// Semaphore.swift
// XIONControlPanel
//
// Created by Charles Magahern on 1/18/16.
// Copyright © 2016 XION. All rights reserved.
//
import Foundation
class Semaphore
{
private var _semaphore: dispatch_semaphore_t
init(value: Int)
{
_semaphore = dispatch_semaphore_create(value)
}
func wait()
{
self.wait(nil)
}
func wait(untilDate: NSDate?)
{
var time: dispatch_time_t = DISPATCH_TIME_FOREVER
if (untilDate != nil) {
time = UInt64(untilDate!.timeIntervalSinceNow) * NSEC_PER_SEC
}
dispatch_semaphore_wait(_semaphore, time)
}
func signal()
{
dispatch_semaphore_signal(_semaphore)
}
}