perf: in Bb_queue, only signal condition on push if queue was empty

This commit is contained in:
Simon Cruanes 2023-08-23 20:43:44 -04:00
parent 18d5bad2a9
commit 0f670c47d3
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -29,8 +29,9 @@ let push (self : _ t) x : unit =
Mutex.unlock self.mutex;
raise Closed
) else (
let was_empty = Queue.is_empty self.q in
Queue.push x self.q;
Condition.signal self.cond;
if was_empty then Condition.broadcast self.cond;
Mutex.unlock self.mutex
)
@ -79,8 +80,9 @@ let try_push (self : _ t) x : bool =
raise Closed
);
let was_empty = Queue.is_empty self.q in
Queue.push x self.q;
Condition.signal self.cond;
if was_empty then Condition.broadcast self.cond;
Mutex.unlock self.mutex;
true
) else