package opentelemetry-client

  1. Overview
  2. Docs
Client SDK for https://opentelemetry.io

Install

dune-project
 Dependency

Authors

Maintainers

Sources

opentelemetry-0.91.1.tbz
sha256=30f344e7168a793d02c12d69c0f566b06eb963f52db3321e415ef6c5cd3d504d
sha512=19160da37cab59a23333d815baa67035f666e700a386953ec9957c685a0b72fa87919bac6a6651e50b1619773b3be7170bcc067c2d5316436b988bcf8d18dcba

doc/src/opentelemetry-client.sync/sync_queue.ml.html

Source file sync_queue.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module UM = Util_mutex

type 'a t = {
  mutex: Mutex.t;
  cond: Condition.t;
  q: 'a Queue.t;
  mutable closed: bool;
}

exception Closed

let create () : _ t =
  {
    mutex = Mutex.create ();
    cond = Condition.create ();
    q = Queue.create ();
    closed = false;
  }

let close (self : _ t) =
  UM.protect self.mutex @@ fun () ->
  if not self.closed then (
    self.closed <- true;
    Condition.broadcast self.cond (* awake waiters so they fail  *)
  )

let push (self : _ t) x : unit =
  UM.protect self.mutex @@ fun () ->
  if self.closed then
    raise Closed
  else (
    Queue.push x self.q;
    Condition.signal self.cond
  )

let pop (self : 'a t) : 'a =
  let rec loop () =
    if self.closed then
      raise Closed
    else if Queue.is_empty self.q then (
      Condition.wait self.cond self.mutex;
      (loop [@tailcall]) ()
    ) else (
      let x = Queue.pop self.q in
      x
    )
  in
  UM.protect self.mutex loop

let pop_all (self : 'a t) into : unit =
  let rec loop () =
    if Queue.is_empty self.q then (
      if self.closed then raise Closed;
      Condition.wait self.cond self.mutex;
      (loop [@tailcall]) ()
    ) else
      Queue.transfer self.q into
  in
  UM.protect self.mutex loop