Skip to content

Commit e81e1f5

Browse files
committed
Move Condition.signal outside of lock
1 parent 67372e0 commit e81e1f5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/chan.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ let send' {buffer_size; contents} v ~polling =
9191
let new_contents = Empty {receivers= receivers'} in
9292
if Atomic.compare_and_set contents old_contents new_contents
9393
then begin
94-
Domain.Mutex.lock mc.mutex;
9594
r := Some v;
96-
Domain.Condition.signal mc.condition;
95+
Domain.Mutex.lock mc.mutex;
9796
Domain.Mutex.unlock mc.mutex;
97+
Domain.Condition.signal mc.condition;
9898
true
9999
end else loop ()
100100
end
@@ -200,10 +200,10 @@ let recv' {buffer_size; contents} ~polling =
200200
in
201201
if Atomic.compare_and_set contents old_contents new_contents
202202
then begin
203-
Domain.Mutex.lock mc.mutex;
204203
c := Notified;
205-
Domain.Condition.signal mc.condition;
204+
Domain.Mutex.lock mc.mutex;
206205
Domain.Mutex.unlock mc.mutex;
206+
Domain.Condition.signal mc.condition;
207207
Some m
208208
end else loop ()
209209
| Some (m, messages'), Some ((ms, sc, mc), senders') ->
@@ -214,10 +214,10 @@ let recv' {buffer_size; contents} ~polling =
214214
in
215215
if Atomic.compare_and_set contents old_contents new_contents
216216
then begin
217-
Domain.Mutex.lock mc.mutex;
218217
sc := Notified;
219-
Domain.Condition.signal mc.condition;
218+
Domain.Mutex.lock mc.mutex;
220219
Domain.Mutex.unlock mc.mutex;
220+
Domain.Condition.signal mc.condition;
221221
Some m
222222
end else loop ()
223223
in

0 commit comments

Comments
 (0)