mirror of
https://github.com/ocaml-tracing/ocaml-trace.git
synced 2026-03-08 03:47:57 -04:00
b_queue: add transfer_into for moving batches into the queue
This commit is contained in:
parent
f3ae3397de
commit
157957530a
2 changed files with 18 additions and 0 deletions
|
|
@ -71,3 +71,18 @@ let transfer (self : 'a t) q2 : unit =
|
|||
do
|
||||
()
|
||||
done
|
||||
|
||||
let transfer_into q (self : _ t) : unit =
|
||||
if not (Queue.is_empty q) then (
|
||||
Mutex.lock self.mutex;
|
||||
|
||||
if self.closed then (
|
||||
Mutex.unlock self.mutex;
|
||||
raise Closed
|
||||
);
|
||||
|
||||
let was_empty = Queue.is_empty self.q in
|
||||
Queue.transfer q self.q;
|
||||
if was_empty then Condition.broadcast self.cond;
|
||||
Mutex.unlock self.mutex
|
||||
)
|
||||
|
|
|
|||
|
|
@ -19,5 +19,8 @@ val transfer : 'a t -> 'a Queue.t -> unit
|
|||
in [bq] into [q2], and clears [bq].
|
||||
It blocks if no element is in [bq]. *)
|
||||
|
||||
val transfer_into : 'a Queue.t -> 'a t -> unit
|
||||
(** [transfer q bq] transfers all items from [q] to [bq]. *)
|
||||
|
||||
val close : _ t -> unit
|
||||
(** Close the queue, meaning there won't be any more [push] allowed. *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue