ocaml-trace/src/fuchsia/buf_pool.ml
Simon Cruanes 190f70d7c9
feat fuchsia: full revamp of the library, modularized
- separate exporter, writer, subscriber
- use the subscriber span tbl to keep track of context
- use a `Buf_chain.t` to keep multiple buffers in use,
  and keep a set of ready buffers
- batch write the ready buffers and then recycle them
2025-05-07 15:33:34 -04:00

23 lines
527 B
OCaml

open Common_
open Trace_private_util
type t = Buf.t Rpool.t
let create ?(max_size = 64) () : t =
Rpool.create ~max_size ~clear:Buf.clear
~create:(fun () -> Buf.create fuchsia_buf_size)
()
let alloc = Rpool.alloc
let[@inline] recycle self buf = if buf != Buf.empty then Rpool.recycle self buf
let with_ (self : t) f =
let x = alloc self in
try
let res = f x in
recycle self x;
res
with e ->
let bt = Printexc.get_raw_backtrace () in
recycle self x;
Printexc.raise_with_backtrace e bt