package xapi-stdext-threads
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Xapi's standard library extension, Threads
Install
dune-project
Dependency
Authors
Maintainers
Sources
xapi-stdext-4.20.0.tbz
sha256=ec93bcab02739d32f8ef09c30db57101bba7d58bb9a503a57dbfc9d81644b4e6
sha512=30db713ad51a9b1dc806bbb88aecec19ed22598a3c23da26aa80cbba431ba18b67e7f6e3834f1a848e75bfb9beeee2a171ddf0547f8c08f36c119a804aeaaf68
doc/src/xapi-stdext-threads/semaphore.ml.html
Source file semaphore.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 50 51 52 53 54 55 56 57 58 59 60 61 62(* * Copyright (C) Citrix Systems Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; version 2.1 only. with the special * exception on linking described in file LICENSE. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. *) type t = { mutable n : int; m : Mutex.t; c : Condition.t; } let create n = if n <= 0 then invalid_arg (Printf.sprintf "Semaphore value must be positive, got %d" n); let m = Mutex.create () and c = Condition.create () in { n; m; c; } exception Inconsistent_state of string let inconsistent_state fmt = Printf.kprintf (fun msg -> raise (Inconsistent_state msg)) fmt let acquire s k = if k <= 0 then invalid_arg (Printf.sprintf "Semaphore acquisition requires a positive value, got %d" k); Mutex.lock s.m; while s.n < k do Condition.wait s.c s.m; done; if not (s.n >= k) then inconsistent_state "Semaphore value cannot be smaller than %d, got %d" k s.n; s.n <- s.n - k; Condition.signal s.c; Mutex.unlock s.m let release s k = if k <= 0 then invalid_arg (Printf.sprintf "Semaphore release requires a positive value, got %d" k); Mutex.lock s.m; s.n <- s.n + k; Condition.signal s.c; Mutex.unlock s.m let execute_with_weight s k f = acquire s k; Xapi_stdext_pervasives.Pervasiveext.finally f (fun () -> release s k) let execute s f = execute_with_weight s 1 f
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>