File: netmcore_queue.mli

package info (click to toggle)
ocamlnet 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 51,764 kB
  • ctags: 16,446
  • sloc: ml: 148,419; ansic: 10,989; sh: 1,885; makefile: 1,355
file content (92 lines) | stat: -rw-r--r-- 3,010 bytes parent folder | download | duplicates (6)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
(* $Id$ *)

(** Shared queues *)

type ('e, 'h) squeue
  (** Queues where the elements have type ['e] and the header has
      type ['h]
   *)

type ('e,'h) squeue_descr
  (** The marshallble descriptor of queues *)

exception Empty
  (** Raised when the queue is empty and the operation cannot be done *)

val create : Netmcore.res_id -> 'h -> ('e,'h) squeue
  (** [create pool h]: Creates an empty queue in the [pool], with header
      [h]
   *)

val push : 'e -> ('e,'h) squeue -> unit
  (** [push x q]: Pushes a copy of [x] to the end of the queue [q] *)

val pop_p : ('e,'h) squeue -> ('e -> 'a) -> 'a
  (** [pop_p q f]: Takes the first element [x] from the queue, removes it
      there, and calls [f x]. During the execution of [f] the value [x]
      is pinned and cannot be garbage-collected.

      Raises [Empty] if the queue is empty.
   *)

val pop_c : ('e,'h) squeue -> 'e
  (** [pop_c q]: Takes the first element [x] from the queue, removes it
      there, and returns a copy of [x] in normal memory.

      Raises [Empty] if the queue is empty.
   *)

val top_p : ('e,'h) squeue -> ('e -> 'a) -> 'a
  (** [pop_p q f]: Takes the first element [x] of the queue, 
      and calls [f x], without removing [x] from the queue. 
      During the execution of [f] the value [x]
      is pinned and cannot be garbage-collected.

      Raises [Empty] if the queue is empty.
   *)

val top_c : ('e,'h) squeue -> 'e
  (** [pop_p q f]: Takes the first element [x] of the queue, 
      and calls [f x], without removing [x] from the queue. 
      Returns a copy of [x] in normal memory.

      Raises [Empty] if the queue is empty.
   *)

val clear : ('e,'h) squeue -> unit
  (** Removes all elements from the queue *)

val is_empty : ('e,'h) squeue -> bool
  (** Tests whether the queue is empty *)

val length : ('e,'h) squeue -> int
  (** Returns the number of elements in the queue (O(1)) *)

val iter : ('e -> unit) -> ('e,'h) squeue -> unit
  (** [iter f q]: Iterates over the elements of the queue and calls [f x]
      for each element [x]. The function considers the list of elements
      at the time of calling [iter] as the list to iterate over. The
      queue is not locked during the iteration, and hence elements can be
      popped from the queue and pushed to the queue in parallel. The
      iteration does not take these modifications into account, though.

      The elements [x] are pinned during the execution of [f] and will
      not be garbage-collected, even if a parallel [pop] removes them from
      the queue.
   *)

val fold : ('a -> 'e -> 'a) -> 'a -> ('e,'h) squeue -> 'a
  (** [fold f accu q] *)

val header : ('e,'h) squeue -> 'h
  (** Returns the header *)

val heap : (_,_) squeue -> Obj.t Netmcore_heap.heap
  (** Returns the underlying heap *)

val descr_of_squeue : ('e,'h) squeue -> ('e,'h) squeue_descr
  (** Returns the descriptor *)

val squeue_of_descr : Netmcore.res_id -> ('e,'h) squeue_descr -> ('e,'h) squeue
  (** Look up the queue for this descriptor *)