package moonpool

  1. Overview
  2. Docs

Module Moonpool.LockSource

Mutex-protected resource.

  • since 0.3
Sourcetype 'a t

A value protected by a mutex

Sourceval create : 'a -> 'a t

Create a new protected value.

Sourceval with_ : 'a t -> ('a -> 'b) -> 'b

with_ l f runs f x where x is the value protected with the lock l, in a critical section. If f x fails, with_lock l f fails too but the lock is released.

Sourceval update : 'a t -> ('a -> 'a) -> unit

update l f replaces the content x of l with f x, while protected by the mutex.

Sourceval update_map : 'a t -> ('a -> 'a * 'b) -> 'b

update_map l f computes x', y = f (get l), then puts x' in l and returns y, while protected by the mutex.

Sourceval mutex : _ t -> Mutex.t

Underlying mutex.

Sourceval get : 'a t -> 'a

Atomically get the value in the lock. The value that is returned isn't protected!

Sourceval set : 'a t -> 'a -> unit

Atomically set the value.

NOTE caution: using get and set as if this were a ref is an anti pattern and will not protect data against some race conditions.

OCaml

Innovation. Community. Security.