From af4ee4dc27702c91ee0ad0e8f0ef132eba661887 Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Fri, 7 Jun 2024 10:35:15 +0200 Subject: [PATCH] Improve condvar signaling --- src/data_structures/wq.ml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/data_structures/wq.ml b/src/data_structures/wq.ml index 67e4a3f56..531780665 100644 --- a/src/data_structures/wq.ml +++ b/src/data_structures/wq.ml @@ -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 = @@ -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 =