ocaml-containers/1.4/CCLock.html
2017-12-24 16:48:20 +01:00

198 lines
No EOL
12 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="Start" href="index.html">
<link rel="previous" href="CCPool.html">
<link rel="next" href="CCSemaphore.html">
<link rel="Up" href="index.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of class methods" rel=Appendix href="index_methods.html">
<link title="Index of class types" rel=Appendix href="index_class_types.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="Index of module types" rel=Appendix href="index_module_types.html">
<link title="CCVector" rel="Chapter" href="CCVector.html">
<link title="CCHeap" rel="Chapter" href="CCHeap.html">
<link title="CCList" rel="Chapter" href="CCList.html">
<link title="CCOpt" rel="Chapter" href="CCOpt.html">
<link title="CCPair" rel="Chapter" href="CCPair.html">
<link title="CCFun" rel="Chapter" href="CCFun.html">
<link title="CCHash" rel="Chapter" href="CCHash.html">
<link title="CCInt" rel="Chapter" href="CCInt.html">
<link title="CCBool" rel="Chapter" href="CCBool.html">
<link title="CCFloat" rel="Chapter" href="CCFloat.html">
<link title="CCArray" rel="Chapter" href="CCArray.html">
<link title="CCRef" rel="Chapter" href="CCRef.html">
<link title="CCSet" rel="Chapter" href="CCSet.html">
<link title="CCOrd" rel="Chapter" href="CCOrd.html">
<link title="CCRandom" rel="Chapter" href="CCRandom.html">
<link title="CCString" rel="Chapter" href="CCString.html">
<link title="CCHashtbl" rel="Chapter" href="CCHashtbl.html">
<link title="CCMap" rel="Chapter" href="CCMap.html">
<link title="CCFormat" rel="Chapter" href="CCFormat.html">
<link title="CCIO" rel="Chapter" href="CCIO.html">
<link title="CCInt64" rel="Chapter" href="CCInt64.html">
<link title="CCChar" rel="Chapter" href="CCChar.html">
<link title="CCResult" rel="Chapter" href="CCResult.html">
<link title="CCParse" rel="Chapter" href="CCParse.html">
<link title="CCArray_slice" rel="Chapter" href="CCArray_slice.html">
<link title="CCListLabels" rel="Chapter" href="CCListLabels.html">
<link title="CCArrayLabels" rel="Chapter" href="CCArrayLabels.html">
<link title="CCEqual" rel="Chapter" href="CCEqual.html">
<link title="Containers" rel="Chapter" href="Containers.html">
<link title="CCKTree" rel="Chapter" href="CCKTree.html">
<link title="CCKList" rel="Chapter" href="CCKList.html">
<link title="CCLazy_list" rel="Chapter" href="CCLazy_list.html">
<link title="CCMultiMap" rel="Chapter" href="CCMultiMap.html">
<link title="CCMultiSet" rel="Chapter" href="CCMultiSet.html">
<link title="CCTrie" rel="Chapter" href="CCTrie.html">
<link title="CCFlatHashtbl" rel="Chapter" href="CCFlatHashtbl.html">
<link title="CCCache" rel="Chapter" href="CCCache.html">
<link title="CCPersistentHashtbl" rel="Chapter" href="CCPersistentHashtbl.html">
<link title="CCDeque" rel="Chapter" href="CCDeque.html">
<link title="CCFQueue" rel="Chapter" href="CCFQueue.html">
<link title="CCBV" rel="Chapter" href="CCBV.html">
<link title="CCMixtbl" rel="Chapter" href="CCMixtbl.html">
<link title="CCMixmap" rel="Chapter" href="CCMixmap.html">
<link title="CCRingBuffer" rel="Chapter" href="CCRingBuffer.html">
<link title="CCIntMap" rel="Chapter" href="CCIntMap.html">
<link title="CCPersistentArray" rel="Chapter" href="CCPersistentArray.html">
<link title="CCMixset" rel="Chapter" href="CCMixset.html">
<link title="CCGraph" rel="Chapter" href="CCGraph.html">
<link title="CCHashSet" rel="Chapter" href="CCHashSet.html">
<link title="CCBitField" rel="Chapter" href="CCBitField.html">
<link title="CCHashTrie" rel="Chapter" href="CCHashTrie.html">
<link title="CCWBTree" rel="Chapter" href="CCWBTree.html">
<link title="CCRAL" rel="Chapter" href="CCRAL.html">
<link title="CCSimple_queue" rel="Chapter" href="CCSimple_queue.html">
<link title="CCImmutArray" rel="Chapter" href="CCImmutArray.html">
<link title="CCHet" rel="Chapter" href="CCHet.html">
<link title="CCZipper" rel="Chapter" href="CCZipper.html">
<link title="CCPool" rel="Chapter" href="CCPool.html">
<link title="CCLock" rel="Chapter" href="CCLock.html">
<link title="CCSemaphore" rel="Chapter" href="CCSemaphore.html">
<link title="CCThread" rel="Chapter" href="CCThread.html">
<link title="CCBlockingQueue" rel="Chapter" href="CCBlockingQueue.html">
<link title="CCTimer" rel="Chapter" href="CCTimer.html">
<link title="CCUnix" rel="Chapter" href="CCUnix.html">
<link title="CCSexp" rel="Chapter" href="CCSexp.html">
<link title="CCSexp_lex" rel="Chapter" href="CCSexp_lex.html"><title>Containers doc : CCLock</title>
</head>
<body>
<div class="navbar"><a class="pre" href="CCPool.html" title="CCPool">Previous</a>
&nbsp;<a class="up" href="index.html" title="Index">Up</a>
&nbsp;<a class="post" href="CCSemaphore.html" title="CCSemaphore">Next</a>
</div>
<h1>Module <a href="type_CCLock.html">CCLock</a></h1>
<pre><span class="keyword">module</span> CCLock: <code class="code"><span class="keyword">sig</span></code> <a href="CCLock.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
<h1 id="1_UtilsaroundMutex">Utils around Mutex</h1>
<p>
A value wrapped into a Mutex, for more safety.<br>
<b>Since</b> 0.8<br>
</div>
<hr width="100%">
<pre><span id="TYPEt"><span class="keyword">type</span> <code class="type">'a</code> t</span> </pre>
<div class="info ">
A value surrounded with a lock<br>
</div>
<pre><span id="VALcreate"><span class="keyword">val</span> create</span> : <code class="type">'a -> 'a <a href="CCLock.html#TYPEt">t</a></code></pre><div class="info ">
Create a new protected value<br>
</div>
<pre><span id="VALwith_lock"><span class="keyword">val</span> with_lock</span> : <code class="type">'a <a href="CCLock.html#TYPEt">t</a> -> ('a -> 'b) -> 'b</code></pre><div class="info ">
<code class="code">with_lock&nbsp;l&nbsp;f</code> runs <code class="code">f&nbsp;x</code> where <code class="code">x</code> is the value protected with
the lock <code class="code">l</code>, in a critical section. If <code class="code">f&nbsp;x</code> fails, <code class="code">with_lock&nbsp;l&nbsp;f</code>
fails too but the lock is released<br>
</div>
<pre><span id="VALtry_with_lock"><span class="keyword">val</span> try_with_lock</span> : <code class="type">'a <a href="CCLock.html#TYPEt">t</a> -> ('a -> 'b) -> 'b option</code></pre><div class="info ">
<code class="code">try_with_lock&nbsp;l&nbsp;f</code> runs <code class="code">f&nbsp;x</code> in a critical section if <code class="code">l</code> is not
locked. <code class="code">x</code> is the value protected by the lock <code class="code">l</code>. If <code class="code">f&nbsp;x</code>
fails, <code class="code">try_with_lock&nbsp;l&nbsp;f</code> fails too but the lock is released<br>
<b>Since</b> 0.22<br>
</div>
<pre><span class="keyword">module</span> <a href="CCLock.LockRef.html">LockRef</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCLock.LockRef.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info">
Type allowing to manipulate the lock as a reference
</div>
<pre><span id="VALwith_lock_as_ref"><span class="keyword">val</span> with_lock_as_ref</span> : <code class="type">'a <a href="CCLock.html#TYPEt">t</a> -> f:('a <a href="CCLock.LockRef.html#TYPEt">LockRef.t</a> -> 'b) -> 'b</code></pre><div class="info ">
<code class="code">with_lock_as_ref&nbsp;l&nbsp;f</code> calls <code class="code">f</code> with a reference-like object
that allows to manipulate the value of <code class="code">l</code> safely.
The object passed to <code class="code">f</code> must not escape the function call<br>
<b>Since</b> 0.13<br>
</div>
<pre><span id="VALupdate"><span class="keyword">val</span> update</span> : <code class="type">'a <a href="CCLock.html#TYPEt">t</a> -> ('a -> 'a) -> unit</code></pre><div class="info ">
<code class="code">update&nbsp;l&nbsp;f</code> replaces the content <code class="code">x</code> of <code class="code">l</code> with <code class="code">f&nbsp;x</code>, atomically<br>
</div>
<pre><span id="VALupdate_map"><span class="keyword">val</span> update_map</span> : <code class="type">'a <a href="CCLock.html#TYPEt">t</a> -> ('a -> 'a * 'b) -> 'b</code></pre><div class="info ">
<code class="code">update_map&nbsp;l&nbsp;f</code> computes <code class="code">x',&nbsp;y&nbsp;=&nbsp;f&nbsp;(get&nbsp;l)</code>, then puts <code class="code">x'</code> in <code class="code">l</code>
and returns <code class="code">y</code><br>
<b>Since</b> 0.16<br>
</div>
<pre><span id="VALmutex"><span class="keyword">val</span> mutex</span> : <code class="type">'a <a href="CCLock.html#TYPEt">t</a> -> Mutex.t</code></pre><div class="info ">
Underlying mutex<br>
</div>
<pre><span id="VALget"><span class="keyword">val</span> get</span> : <code class="type">'a <a href="CCLock.html#TYPEt">t</a> -> 'a</code></pre><div class="info ">
Atomically get the value in the lock. The value that is returned
isn't protected!<br>
</div>
<pre><span id="VALset"><span class="keyword">val</span> set</span> : <code class="type">'a <a href="CCLock.html#TYPEt">t</a> -> 'a -> unit</code></pre><div class="info ">
Atomically set the value<br>
<b>Since</b> 0.13<br>
</div>
<pre><span id="VALincr"><span class="keyword">val</span> incr</span> : <code class="type">int <a href="CCLock.html#TYPEt">t</a> -> unit</code></pre><div class="info ">
Atomically increment the value<br>
<b>Since</b> 0.13<br>
</div>
<pre><span id="VALdecr"><span class="keyword">val</span> decr</span> : <code class="type">int <a href="CCLock.html#TYPEt">t</a> -> unit</code></pre><div class="info ">
Atomically decrement the value<br>
<b>Since</b> 0.13<br>
</div>
<pre><span id="VALincr_then_get"><span class="keyword">val</span> incr_then_get</span> : <code class="type">int <a href="CCLock.html#TYPEt">t</a> -> int</code></pre><div class="info ">
<code class="code">incr_then_get&nbsp;x</code> increments <code class="code">x</code>, and return its new value<br>
<b>Since</b> 0.16<br>
</div>
<pre><span id="VALget_then_incr"><span class="keyword">val</span> get_then_incr</span> : <code class="type">int <a href="CCLock.html#TYPEt">t</a> -> int</code></pre><div class="info ">
<code class="code">get_then_incr&nbsp;x</code> increments <code class="code">x</code>, and return its previous value<br>
<b>Since</b> 0.16<br>
</div>
<pre><span id="VALdecr_then_get"><span class="keyword">val</span> decr_then_get</span> : <code class="type">int <a href="CCLock.html#TYPEt">t</a> -> int</code></pre><div class="info ">
<code class="code">decr_then_get&nbsp;x</code> decrements <code class="code">x</code>, and return its new value<br>
<b>Since</b> 0.16<br>
</div>
<pre><span id="VALget_then_decr"><span class="keyword">val</span> get_then_decr</span> : <code class="type">int <a href="CCLock.html#TYPEt">t</a> -> int</code></pre><div class="info ">
<code class="code">get_then_decr&nbsp;x</code> decrements <code class="code">x</code>, and return its previous value<br>
<b>Since</b> 0.16<br>
</div>
<pre><span id="VALget_then_set"><span class="keyword">val</span> get_then_set</span> : <code class="type">bool <a href="CCLock.html#TYPEt">t</a> -> bool</code></pre><div class="info ">
<code class="code">get_then_set&nbsp;b</code> sets <code class="code">b</code> to <code class="code"><span class="keyword">true</span></code>, and return the old value<br>
<b>Since</b> 0.16<br>
</div>
<pre><span id="VALget_then_clear"><span class="keyword">val</span> get_then_clear</span> : <code class="type">bool <a href="CCLock.html#TYPEt">t</a> -> bool</code></pre><div class="info ">
<code class="code">get_then_clear&nbsp;b</code> sets <code class="code">b</code> to <code class="code"><span class="keyword">false</span></code>, and return the old value<br>
<b>Since</b> 0.16<br>
</div>
</body></html>