Skip to content

Commit

Permalink
Move Condition.signal outside of lock
Browse files Browse the repository at this point in the history
  • Loading branch information
ctk21 committed Apr 28, 2021
1 parent 67372e0 commit e81e1f5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/chan.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ let send' {buffer_size; contents} v ~polling =
let new_contents = Empty {receivers= receivers'} in
if Atomic.compare_and_set contents old_contents new_contents
then begin
Domain.Mutex.lock mc.mutex;
r := Some v;
Domain.Condition.signal mc.condition;
Domain.Mutex.lock mc.mutex;
Domain.Mutex.unlock mc.mutex;
Domain.Condition.signal mc.condition;
true
end else loop ()
end
Expand Down Expand Up @@ -200,10 +200,10 @@ let recv' {buffer_size; contents} ~polling =
in
if Atomic.compare_and_set contents old_contents new_contents
then begin
Domain.Mutex.lock mc.mutex;
c := Notified;
Domain.Condition.signal mc.condition;
Domain.Mutex.lock mc.mutex;
Domain.Mutex.unlock mc.mutex;
Domain.Condition.signal mc.condition;
Some m
end else loop ()
| Some (m, messages'), Some ((ms, sc, mc), senders') ->
Expand All @@ -214,10 +214,10 @@ let recv' {buffer_size; contents} ~polling =
in
if Atomic.compare_and_set contents old_contents new_contents
then begin
Domain.Mutex.lock mc.mutex;
sc := Notified;
Domain.Condition.signal mc.condition;
Domain.Mutex.lock mc.mutex;
Domain.Mutex.unlock mc.mutex;
Domain.Condition.signal mc.condition;
Some m
end else loop ()
in
Expand Down

0 comments on commit e81e1f5

Please sign in to comment.