Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve condvar signaling #323

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading