mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
2 lines
No EOL
8.4 KiB
HTML
2 lines
No EOL
8.4 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>CCLock (containers.CCLock)</title><link rel="stylesheet" href="../../odoc.css"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> – <a href="../index.html">containers</a> » CCLock</nav><h1>Module <code>CCLock</code></h1><h2 id="utils-around-mutex"><a href="#utils-around-mutex" class="anchor"></a>Utils around Mutex</h2><p>A value wrapped into a Mutex, for more safety.</p><dl><dt>since</dt><dd>0.8</dd></dl></header><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type </span>'a t</code></dt><dd><p>A value surrounded with a lock</p></dd></dl><dl><dt class="spec value" id="val-create"><a href="#val-create" class="anchor"></a><code><span class="keyword">val </span>create : <span class="type-var">'a</span> <span>-></span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Create a new protected value.</p></dd></dl><dl><dt class="spec value" id="val-with_lock"><a href="#val-with_lock" class="anchor"></a><code><span class="keyword">val </span>with_lock : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span>) <span>-></span> <span class="type-var">'b</span></code></dt><dd><p><code>with_lock l f</code> runs <code>f x</code> where <code>x</code> is the value protected with the lock <code>l</code>, in a critical section. If <code>f x</code> fails, <code>with_lock l f</code> fails too but the lock is released.</p></dd></dl><dl><dt class="spec value" id="val-try_with_lock"><a href="#val-try_with_lock" class="anchor"></a><code><span class="keyword">val </span>try_with_lock : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'b</span>) <span>-></span> <span class="type-var">'b</span> option</code></dt><dd><p><code>try_with_lock l f</code> runs <code>f x</code> in a critical section if <code>l</code> is not locked. <code>x</code> is the value protected by the lock <code>l</code>. If <code>f x</code> fails, <code>try_with_lock l f</code> fails too but the lock is released.</p><dl><dt>since</dt><dd>0.22</dd></dl></dd></dl><dl><dt class="spec module" id="module-LockRef"><a href="#module-LockRef" class="anchor"></a><code><span class="keyword">module </span><a href="LockRef/index.html">LockRef</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></dt><dd><p>Type allowing to manipulate the lock as a reference.</p></dd></dl><dl><dt class="spec value" id="val-with_lock_as_ref"><a href="#val-with_lock_as_ref" class="anchor"></a><code><span class="keyword">val </span>with_lock_as_ref : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> f:(<span class="type-var">'a</span> <a href="LockRef/index.html#type-t">LockRef.t</a> <span>-></span> <span class="type-var">'b</span>) <span>-></span> <span class="type-var">'b</span></code></dt><dd><p><code>with_lock_as_ref l f</code> calls <code>f</code> with a reference-like object that allows to manipulate the value of <code>l</code> safely. The object passed to <code>f</code> must not escape the function call.</p><dl><dt>since</dt><dd>0.13</dd></dl></dd></dl><dl><dt class="spec value" id="val-update"><a href="#val-update" class="anchor"></a><code><span class="keyword">val </span>update : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'a</span>) <span>-></span> unit</code></dt><dd><p><code>update l f</code> replaces the content <code>x</code> of <code>l</code> with <code>f x</code>, atomically.</p></dd></dl><dl><dt class="spec value" id="val-update_map"><a href="#val-update_map" class="anchor"></a><code><span class="keyword">val </span>update_map : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> (<span class="type-var">'a</span> <span>-></span> <span class="type-var">'a</span><span class="keyword"> * </span><span class="type-var">'b</span>) <span>-></span> <span class="type-var">'b</span></code></dt><dd><p><code>update_map l f</code> computes <code>x', y = f (get l)</code>, then puts <code>x'</code> in <code>l</code> and returns <code>y</code>.</p><dl><dt>since</dt><dd>0.16</dd></dl></dd></dl><dl><dt class="spec value" id="val-mutex"><a href="#val-mutex" class="anchor"></a><code><span class="keyword">val </span>mutex : <span class="type-var">_</span> <a href="index.html#type-t">t</a> <span>-></span> Mutex.t</code></dt><dd><p>Underlying mutex.</p></dd></dl><dl><dt class="spec value" id="val-get"><a href="#val-get" class="anchor"></a><code><span class="keyword">val </span>get : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'a</span></code></dt><dd><p>Atomically get the value in the lock. The value that is returned isn't protected!</p></dd></dl><dl><dt class="spec value" id="val-set"><a href="#val-set" class="anchor"></a><code><span class="keyword">val </span>set : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'a</span> <span>-></span> unit</code></dt><dd><p>Atomically set the value.</p><dl><dt>since</dt><dd>0.13</dd></dl></dd></dl><dl><dt class="spec value" id="val-incr"><a href="#val-incr" class="anchor"></a><code><span class="keyword">val </span>incr : int <a href="index.html#type-t">t</a> <span>-></span> unit</code></dt><dd><p>Atomically increment the value.</p><dl><dt>since</dt><dd>0.13</dd></dl></dd></dl><dl><dt class="spec value" id="val-decr"><a href="#val-decr" class="anchor"></a><code><span class="keyword">val </span>decr : int <a href="index.html#type-t">t</a> <span>-></span> unit</code></dt><dd><p>Atomically decrement the value.</p><dl><dt>since</dt><dd>0.13</dd></dl></dd></dl><dl><dt class="spec value" id="val-incr_then_get"><a href="#val-incr_then_get" class="anchor"></a><code><span class="keyword">val </span>incr_then_get : int <a href="index.html#type-t">t</a> <span>-></span> int</code></dt><dd><p><code>incr_then_get x</code> increments <code>x</code>, and returns its new value.</p><dl><dt>since</dt><dd>0.16</dd></dl></dd></dl><dl><dt class="spec value" id="val-get_then_incr"><a href="#val-get_then_incr" class="anchor"></a><code><span class="keyword">val </span>get_then_incr : int <a href="index.html#type-t">t</a> <span>-></span> int</code></dt><dd><p><code>get_then_incr x</code> increments <code>x</code>, and returns its previous value.</p><dl><dt>since</dt><dd>0.16</dd></dl></dd></dl><dl><dt class="spec value" id="val-decr_then_get"><a href="#val-decr_then_get" class="anchor"></a><code><span class="keyword">val </span>decr_then_get : int <a href="index.html#type-t">t</a> <span>-></span> int</code></dt><dd><p><code>decr_then_get x</code> decrements <code>x</code>, and returns its new value.</p><dl><dt>since</dt><dd>0.16</dd></dl></dd></dl><dl><dt class="spec value" id="val-get_then_decr"><a href="#val-get_then_decr" class="anchor"></a><code><span class="keyword">val </span>get_then_decr : int <a href="index.html#type-t">t</a> <span>-></span> int</code></dt><dd><p><code>get_then_decr x</code> decrements <code>x</code>, and returns its previous value.</p><dl><dt>since</dt><dd>0.16</dd></dl></dd></dl><dl><dt class="spec value" id="val-get_then_set"><a href="#val-get_then_set" class="anchor"></a><code><span class="keyword">val </span>get_then_set : bool <a href="index.html#type-t">t</a> <span>-></span> bool</code></dt><dd><p><code>get_then_set b</code> sets <code>b</code> to <code>true</code>, and returns the old value.</p><dl><dt>since</dt><dd>0.16</dd></dl></dd></dl><dl><dt class="spec value" id="val-get_then_clear"><a href="#val-get_then_clear" class="anchor"></a><code><span class="keyword">val </span>get_then_clear : bool <a href="index.html#type-t">t</a> <span>-></span> bool</code></dt><dd><p><code>get_then_clear b</code> sets <code>b</code> to <code>false</code>, and returns the old value.</p><dl><dt>since</dt><dd>0.16</dd></dl></dd></dl></div></body></html> |