package trace

  1. Overview
  2. Docs
A stub for tracing/observability, agnostic in how data is collected

Install

Dune Dependency

Authors

Maintainers

Sources

trace-0.8.tbz
sha256=34cfa5662b611c1e246f0fb8131ee605eeb90b359c105e882f51adc7e70878c3
sha512=ea47974a77a0ab26c58fe6d1bc898d4f3e6a5f865e4c1acb4188b9acd7ba8e7527d0ea7f2ae66574ceccc14f11127ee203aedba2be334d17b36c83dabff61261

doc/src/trace_private_util/mpsc_bag.ml.html

Source file mpsc_bag.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module A = Trace_core.Internal_.Atomic_

type 'a t = { bag: 'a list A.t } [@@unboxed]

let create () =
  let bag = A.make [] in
  { bag }

module Backoff = struct
  type t = int

  let default = 2

  let once (b : t) : t =
    for _i = 1 to b do
      Domain_util.cpu_relax ()
    done;
    min (b * 2) 256
end

let rec add backoff t x =
  let before = A.get t.bag in
  let after = x :: before in
  if not (A.compare_and_set t.bag before after) then
    add (Backoff.once backoff) t x

let[@inline] add t x = add Backoff.default t x

let[@inline] pop_all t : _ list option =
  match A.exchange t.bag [] with
  | [] -> None
  | l -> Some (List.rev l)
OCaml

Innovation. Community. Security.