package par_incr

  1. Overview
  2. Docs

Source file reader_list.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
type t = Rsp.RNode.t list Atomic.t

let empty () = Atomic.make []

let[@tail_mod_cons] rec remove_first x' = function
  | [] -> []
  | x :: xs -> if x == x' then xs else x :: remove_first x' xs

let rec remove_reader t node =
  let nodes = Atomic.get t in
  if not (Atomic.compare_and_set t nodes (remove_first node nodes)) then
    remove_reader t node

let rec add_reader t node =
  let nodes = Atomic.get t in
  if not (Atomic.compare_and_set t nodes (node :: nodes)) then add_reader t node

let[@inline] iter t f = List.iter f (Atomic.get t)
let length t = List.length (Atomic.get t)