File: semaphore.mli

package info (click to toggle)
ocaml-eio 1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,548 kB
  • sloc: ml: 14,608; ansic: 1,237; makefile: 25
file content (27 lines) | stat: -rw-r--r-- 1,077 bytes parent folder | download
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
(** The API is based on OCaml's [Semaphore.Counting].

    The difference is that when waiting for the semaphore this will switch to the next runnable fiber,
    whereas the stdlib one will block the whole domain.

    Semaphores are thread-safe and so can be shared between domains and used
    to synchronise between them. *)

type t
(** The type of counting semaphores. *)

val make : int -> t
(** [make n] returns a new counting semaphore, with initial value [n].
    The initial value [n] must be nonnegative.
    @raise Invalid_argument if [n < 0] *)

val release : t -> unit
(** [release t] increments the value of semaphore [t].
    If other fibers are waiting on [t], the one that has been waiting the longest is resumed.
    @raise Sys_error if the value of the semaphore would overflow [max_int] *)

val acquire : t -> unit
(** [acquire t] blocks the calling fiber until the value of semaphore [t]
    is not zero, then atomically decrements the value of [t] and returns. *)

val get_value : t -> int
(** [get_value t] returns the current value of semaphore [t]. *)