Conversion to Swift3

This commit is contained in:
Charles Magahern
2017-05-13 00:40:03 -07:00
parent 687b45c73a
commit 091af0844a
16 changed files with 353 additions and 325 deletions
+11 -8
View File
@@ -10,11 +10,11 @@ import Foundation
class Semaphore
{
private var _semaphore: dispatch_semaphore_t
fileprivate var _semaphore: DispatchSemaphore
init(value: Int)
{
_semaphore = dispatch_semaphore_create(value)
_semaphore = DispatchSemaphore(value: value)
}
func wait()
@@ -22,18 +22,21 @@ class Semaphore
self.wait(nil)
}
func wait(untilDate: NSDate?)
func wait(_ untilDate: Date?)
{
var time: dispatch_time_t = DISPATCH_TIME_FOREVER
if (untilDate != nil) {
time = UInt64(untilDate!.timeIntervalSinceNow) * NSEC_PER_SEC
var time: DispatchTime = DispatchTime.distantFuture
if let untilDate = untilDate {
time = .now() + .milliseconds(Int(untilDate.timeIntervalSinceNow * 1000))
}
dispatch_semaphore_wait(_semaphore, time)
let result = _semaphore.wait(timeout: time)
if (result != .success) {
print("semaphore timed out")
}
}
func signal()
{
dispatch_semaphore_signal(_semaphore)
_semaphore.signal()
}
}