package picos_std
Sample libraries for Picos
Install
Dune Dependency
Authors
Maintainers
Sources
picos-0.5.0.tbz
sha256=862d61383e2df93a876bedcffb1fd1ddc0f96c50b0e9c07943a2aee1f0e182be
sha512=87805379017ef4a7f2c11b954625a3757a0f1431bb9ba59132202de278b3e41adbe0cdc20e3ab23b7c9a8c5a15faeb7ec79348e7d80f2b14274b00df0893b8c0
doc/src/picos_std.sync/latch.ml.html
Source file latch.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
open Picos open Picos_std_event let[@inline never] negative_count () = invalid_arg "negative count" let[@inline never] zero_count () = invalid_arg "zero count" type t = { count : int Atomic.t; computation : unit Computation.t } let zero = Atomic.make 0 let create ?padded n = if n < 0 then negative_count (); let count = if 0 < n then Atomic.make n |> Multicore_magic.copy_as ?padded else zero and computation = if n <= 0 then Computation.finished else Computation.create () in Multicore_magic.copy_as ?padded { count; computation } type _ result = | Unit : unit result (** [Unit] is physically same as [()]. *) | Bool : bool result (** [Bool] is physically same as [true]. *) let rec try_decr : type a. _ -> a result -> _ -> a = fun t result backoff -> let n = Atomic.get t.count in if 0 < n then if Atomic.compare_and_set t.count n (n - 1) then begin if n = 1 then Computation.finish t.computation; match result with Unit -> () | Bool -> true end else try_decr t result (Backoff.once backoff) else match result with Unit -> zero_count () | Bool -> false let rec try_incr : type a. _ -> a result -> _ -> a = fun t result backoff -> let n = Atomic.get t.count in if 0 < n then if Atomic.compare_and_set t.count n (n + 1) then match result with Unit -> () | Bool -> true else try_incr t result (Backoff.once backoff) else match result with Unit -> zero_count () | Bool -> false let decr t = try_decr t Unit Backoff.default let incr t = try_incr t Unit Backoff.default let try_decr t = try_decr t Bool Backoff.default let try_incr t = try_incr t Bool Backoff.default let await t = Computation.await t.computation let await_evt t = Event.from_computation t.computation
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>