Skip to content

Commit 3ff155d

Browse files
committed
internal seem use
1 parent 425f01e commit 3ff155d

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

ExecutionContext/ExecutionContext.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,16 @@ extension ExecutionContextType {
129129
func syncThroughAsync<ReturnType>(task:() throws -> ReturnType) throws -> ReturnType {
130130
var result:Result<ReturnType, AnyError>?
131131

132-
let cond = NSCondition()
133-
var done = false
132+
let sema = Semaphore()
134133

135134
async {
136135
defer {
137-
cond.lock()
138-
done = true
139-
cond.signal()
140-
cond.unlock()
136+
sema.signal()
141137
}
142138
result = materialize(task)
143139
}
144140

145-
cond.lock()
146-
while !done {
147-
cond.wait()
148-
}
149-
cond.unlock()
141+
sema.wait()
150142

151143
return try result!.dematerializeAnyError()
152144
}

ExecutionContext/PThreadExecutionContext.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@
7373

7474
override init() {
7575
var runLoop:RunLoop?
76-
let cond = NSCondition()
77-
cond.lock()
76+
let sema = Semaphore()
77+
7878
PThread(task: {
7979
runLoop = RunLoop.currentRunLoop(true)
80-
cond.signal()
80+
sema.signal()
8181
RunLoop.run()
8282
}).start()
83-
cond.wait()
84-
cond.unlock()
83+
84+
sema.wait()
85+
8586
self.rl = runLoop!
8687
}
8788

ExecutionContext/Semaphore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public class Semaphore {
4040
self.value = value
4141
}
4242

43-
/// Creates a new semaphore with initial value 1
43+
/// Creates a new semaphore with initial value 0
4444
/// This kind of semaphores is useful to protect a critical section
4545
public convenience init() {
46-
self.init(value: 1)
46+
self.init(value: 0)
4747
}
4848

4949
/// returns true on success (false if timeout expired)

0 commit comments

Comments
 (0)