Skip to content

Commit

Permalink
Improve condvar signaling
Browse files Browse the repository at this point in the history
  • Loading branch information
krtab committed Jun 18, 2024
1 parent bfe3517 commit af4ee4d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/data_structures/wq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let make_pledge q =
let end_pledge q =
Mutex.lock q.mutex;
q.pledges <- q.pledges - 1;
Condition.broadcast q.cond;
if q.pledges = 0 then Condition.broadcast q.cond;
Mutex.unlock q.mutex

let rec read_as_seq (q : 'a t) ~finalizer : 'a Seq.t =
Expand All @@ -49,9 +49,8 @@ let rec read_as_seq (q : 'a t) ~finalizer : 'a Seq.t =

let push v q =
Mutex.lock q.mutex;
let was_empty = Queue.is_empty q.queue in
Queue.push v q.queue;
if was_empty then Condition.broadcast q.cond;
Condition.signal q.cond;
Mutex.unlock q.mutex

let fail q =
Expand Down

0 comments on commit af4ee4d

Please sign in to comment.