Skip to content

Commit

Permalink
Improve condvar signaling
Browse files Browse the repository at this point in the history
  • Loading branch information
krtab authored and zapashcanon committed Dec 4, 2024
1 parent 3b5040f commit 388f06d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/data_structures/synchronizer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ let make_pledge synchro =
let end_pledge synchro =
Mutex.lock synchro.mutex;
synchro.pledges <- synchro.pledges - 1;
Condition.broadcast synchro.cond;
if Int.equal synchro.pledges 0 then Condition.broadcast synchro.cond;
Mutex.unlock synchro.mutex

let fail q =
Expand Down
3 changes: 1 addition & 2 deletions src/data_structures/wq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ let fail = Synchronizer.fail
let make () =
let q = Queue.create () in
let writter v condvar =
let was_empty = Queue.is_empty q in
Queue.push v q;
if was_empty then Condition.broadcast condvar
Condition.signal condvar
in
Synchronizer.init (fun () -> Queue.take_opt q) writter

0 comments on commit 388f06d

Please sign in to comment.