package grenier

  1. Overview
  2. Docs
A collection of various algorithms in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

grenier-v0.11.tbz
sha256=658e1ad6fc5fdce0871975b3ebcb3ec760248be63cdb9ea965e3121cc7478d77
sha512=d9ff83f1b025f34c22af5921444993df219761dcee8d8cb5a940f266df8677278967434b22314c5c82d5d983e4c94c04cd52c4717d5c1f22fbd3a022631fae1c

doc/src/grenier.orderme/order_managed_indir.ml.html

Source file order_managed_indir.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
60
61
62
63
64
65
66
67
68
69
70
71
open Order_indir
type order = t

type t = {
  t : order;
  (* This strange dance with protect is to prevent the GC from collecting
     values in the middle of an operation. *)
  lock : gc_lock;
}

and gc_lock = {
  mutable locks: int;
  mutable forgotten: order list;
}

let lock lock =
  lock.locks <- lock.locks + 1

let unlock lock =
  lock.locks <- lock.locks - 1;
  if lock.locks = 0 then
    match lock.forgotten with
    | [] -> ()
    | forgotten ->
      lock.forgotten <- [];
      List.iter forget forgotten

let forget {lock; t} =
  if lock.locks > 0 then
    lock.forgotten <- t :: lock.forgotten
  else
    forget t

let is_valid t =
  lock t.lock;
  let result = is_valid t.t in
  unlock t.lock;
  result

let root () =
  let t = {t = root (); lock = { locks = 0; forgotten = [] }} in
  Gc.finalise forget t;
  t

let after t =
  lock t.lock;
  let t' = {t = after t.t; lock = t.lock} in
  Gc.finalise forget t';
  unlock t.lock;
  t'

let before t =
  lock t.lock;
  let t' = {t = before t.t; lock = t.lock} in
  Gc.finalise forget t';
  unlock t.lock;
  t'

let same_order t1 t2 =
  same_order t1.t t2.t

let compare t1 t2 =
  compare t1.t t2.t

let cardinal t =
  cardinal t.t

let unsafe_check t msg =
  lock t.lock;
  unsafe_check t.t ("(Order_managed) " ^ msg);
  unlock t.lock
OCaml

Innovation. Community. Security.