diff options
Diffstat (limited to 'docs/doxygen/nel/a02516.html')
-rw-r--r-- | docs/doxygen/nel/a02516.html | 339 |
1 files changed, 339 insertions, 0 deletions
diff --git a/docs/doxygen/nel/a02516.html b/docs/doxygen/nel/a02516.html new file mode 100644 index 00000000..41fdc21e --- /dev/null +++ b/docs/doxygen/nel/a02516.html @@ -0,0 +1,339 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> +<title>NeL: NLMISC::CFastMutex class Reference</title> +<link href="doxygen.css" rel="stylesheet" type="text/css"> +</head><body> +<!-- Generated by Doxygen 1.3.6 --> +<div class="qindex"> <form class="search" action="search.php" method="get"> +<a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a> | <span class="search"><u>S</u>earch for <input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div> +<h1>NLMISC::CFastMutex Class Reference</h1><code>#include <<a class="el" href="a06088.html">mutex.h</a>></code> +<p> +<hr><a name="_details"></a><h2>Detailed Description</h2> +Fast mutex implementation (not fairly) The mutex ARE NOT recursive (ie don't call <a class="el" href="a02516.html#NLMISC_1_1CFastMutexa1">enter()</a> several times on the same mutex from the same thread without having called <a class="el" href="a02516.html#NLMISC_1_1CFastMutexa3">leave()</a>) ; The threads ARE NOT woken-up in the same order as they were put to sleep. The threads ARE NOT woken-up using signals but using Sleep(). This mutex works but is not optimal for multiprocessors because if the mutex is locked, next enter will be sleeped without waiting a little.<p> +Implementation notes:<ul> +<li>Implementated under WIN32</li><li>Other OS use CMutex</li></ul> +<p> +Tested: OK on Windows and Linux single & multi-processor<p> +<pre class="fragment"><div> <a class="code" href="a02516.html#NLMISC_1_1CFastMutexa0">CFastMutex</a> m; + m.enter (); + <span class="comment">// do critical stuffs</span> + m.leave (); + * +</div></pre><dl compact><dt><b>Author:</b></dt><dd>Cyril 'Hulud' Corvazier <p> +Olivier Cado <p> +Nevrax France </dd></dl> +<dl compact><dt><b>Date:</b></dt><dd>2002, 2003 </dd></dl> + +<p> + +<p> +Definition at line <a class="el" href="a06088.html#l00194">194</a> of file <a class="el" href="a06088.html">mutex.h</a>.<table border=0 cellpadding=0 cellspacing=0> +<tr><td></td></tr> +<tr><td colspan=2><br><h2>Public Member Functions</h2></td></tr> +<tr><td class="memItemLeft" nowrap align=right valign=top> </td><td class="memItemRight" valign=bottom><a class="el" href="a02516.html#NLMISC_1_1CFastMutexa0">CFastMutex</a> ()</td></tr> + +<tr><td class="mdescLeft"> </td><td class="mdescRight">Constructor. <a href="#NLMISC_1_1CFastMutexa0"></a><br><br></td></tr> +<tr><td class="memItemLeft" nowrap align=right valign=top>__forceinline void </td><td class="memItemRight" valign=bottom><a class="el" href="a02516.html#NLMISC_1_1CFastMutexa1">enter</a> () volatile</td></tr> + +<tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="a02516.html#NLMISC_1_1CFastMutexa2">init</a> () volatile</td></tr> + +<tr><td class="mdescLeft"> </td><td class="mdescRight">Same as constructor, useful for init in a shared memory block. <a href="#NLMISC_1_1CFastMutexa2"></a><br><br></td></tr> +<tr><td class="memItemLeft" nowrap align=right valign=top>__forceinline void </td><td class="memItemRight" valign=bottom><a class="el" href="a02516.html#NLMISC_1_1CFastMutexa3">leave</a> () volatile</td></tr> + +<tr><td colspan=2><br><h2>Static Public Member Functions</h2></td></tr> +<tr><td class="memItemLeft" nowrap align=right valign=top>__forceinline bool </td><td class="memItemRight" valign=bottom><a class="el" href="a02516.html#NLMISC_1_1CFastMutexe0">atomic_swap</a> (volatile <a class="el" href="a04558.html#a11">uint32</a> *lockPtr)</td></tr> + +<tr><td class="mdescLeft"> </td><td class="mdescRight">Atomic swap. <a href="#NLMISC_1_1CFastMutexe0"></a><br><br></td></tr> +<tr><td colspan=2><br><h2>Private Attributes</h2></td></tr> +<tr><td class="memItemLeft" nowrap align=right valign=top>volatile <a class="el" href="a04558.html#a11">uint32</a> </td><td class="memItemRight" valign=bottom><a class="el" href="a02516.html#NLMISC_1_1CFastMutexr0">_Lock</a></td></tr> + +</table> +<hr><h2>Constructor & Destructor Documentation</h2> +<a class="anchor" name="NLMISC_1_1CFastMutexa0" doxytag="NLMISC::CFastMutex::CFastMutex" ></a><p> +<table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> + <tr> + <td class="mdRow"> + <table cellpadding="0" cellspacing="0" border="0"> + <tr> + <td class="md" nowrap valign="top"> NLMISC::CFastMutex::CFastMutex </td> + <td class="md" valign="top">( </td> + <td class="mdname1" valign="top" nowrap> </td> + <td class="md" valign="top"> ) </td> + <td class="md" nowrap><code> [inline]</code></td> + </tr> + + </table> + </td> + </tr> +</table> +<table cellspacing=5 cellpadding=0 border=0> + <tr> + <td> + + </td> + <td> + +<p> +Constructor. +<p> + +<p> +Definition at line <a class="el" href="a06088.html#l00199">199</a> of file <a class="el" href="a06088.html">mutex.h</a>. +<p> +References <a class="el" href="a06088.html#l00280">_Lock</a>. +<p> +<div class="fragment"><pre>00199 : <a class="code" href="a02516.html#NLMISC_1_1CFastMutexr0">_Lock</a>(0) {} +</pre></div> </td> + </tr> +</table> +<hr><h2>Member Function Documentation</h2> +<a class="anchor" name="NLMISC_1_1CFastMutexe0" doxytag="NLMISC::CFastMutex::atomic_swap" ></a><p> +<table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> + <tr> + <td class="mdRow"> + <table cellpadding="0" cellspacing="0" border="0"> + <tr> + <td class="md" nowrap valign="top"> __forceinline bool NLMISC::CFastMutex::atomic_swap </td> + <td class="md" valign="top">( </td> + <td class="md" nowrap valign="top">volatile <a class="el" href="a04558.html#a11">uint32</a> * </td> + <td class="mdname1" valign="top" nowrap> <em>lockPtr</em> </td> + <td class="md" valign="top"> ) </td> + <td class="md" nowrap><code> [inline, static]</code></td> + </tr> + + </table> + </td> + </tr> +</table> +<table cellspacing=5 cellpadding=0 border=0> + <tr> + <td> + + </td> + <td> + +<p> +Atomic swap. +<p> + +<p> +Definition at line <a class="el" href="a06088.html#l00205">205</a> of file <a class="el" href="a06088.html">mutex.h</a>. +<p> +References <a class="el" href="a06088.html#l00127">ASM_ASWAP_FOR_GCC_XCHG</a>, and <a class="el" href="a05981.html#l00100">uint32</a>. +<p> +Referenced by <a class="el" href="a06088.html#l00238">enter()</a>. +<p> +<div class="fragment"><pre>00206 { +00207 <a class="code" href="a04558.html#a11">uint32</a> result; +00208 <span class="preprocessor">#ifdef NL_OS_WINDOWS</span> +00209 <span class="preprocessor"></span><span class="preprocessor">#ifdef NL_DEBUG_FAST</span> +00210 <span class="preprocessor"></span> <span class="comment">// Workaround for dumb inlining bug (returning of function goes into the choux): push/pop registers</span> +00211 __asm +00212 { +00213 push eax +00214 push ecx +00215 mov ecx,lockPtr +00216 mov eax,1 +00217 xchg [ecx],eax +00218 mov [result],eax +00219 pop ecx +00220 pop eax +00221 } +00222 <span class="preprocessor">#else</span> +00223 <span class="preprocessor"></span> __asm +00224 { +00225 mov ecx,lockPtr +00226 mov eax,1 +00227 xchg [ecx],eax +00228 mov [result],eax +00229 } +00230 <span class="preprocessor">#endif</span> +00231 <span class="preprocessor"></span><span class="preprocessor">#else</span> +00232 <span class="preprocessor"></span> <a class="code" href="a04665.html#a2">ASM_ASWAP_FOR_GCC_XCHG</a> +00233 <span class="preprocessor">#endif // NL_OS_WINDOWS</span> +00234 <span class="preprocessor"></span> <span class="keywordflow">return</span> result != 0; +00235 } +</pre></div> </td> + </tr> +</table> +<a class="anchor" name="NLMISC_1_1CFastMutexa1" doxytag="NLMISC::CFastMutex::enter" ></a><p> +<table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> + <tr> + <td class="mdRow"> + <table cellpadding="0" cellspacing="0" border="0"> + <tr> + <td class="md" nowrap valign="top"> __forceinline void NLMISC::CFastMutex::enter </td> + <td class="md" valign="top">( </td> + <td class="mdname1" valign="top" nowrap> </td> + <td class="md" valign="top"> ) </td> + <td class="md" nowrap> volatile<code> [inline]</code></td> + </tr> + + </table> + </td> + </tr> +</table> +<table cellspacing=5 cellpadding=0 border=0> + <tr> + <td> + + </td> + <td> + +<p> + +<p> +Definition at line <a class="el" href="a06088.html#l00238">238</a> of file <a class="el" href="a06088.html">mutex.h</a>. +<p> +References <a class="el" href="a06088.html#l00280">_Lock</a>, <a class="el" href="a06088.html#l00205">atomic_swap()</a>, and <a class="el" href="a05981.html#l00105">uint</a>. +<p> +Referenced by <a class="el" href="a05490.html#l00209">NLMISC::CBlockMemory< CNode >::__stl_alloc_changeEltSize()</a>, <a class="el" href="a05490.html#l00097">NLMISC::CBlockMemory< CNode >::allocate()</a>, <a class="el" href="a05490.html#l00147">NLMISC::CBlockMemory< CNode >::free()</a>, <a class="el" href="a05490.html#l00185">NLMISC::CBlockMemory< CNode >::purge()</a>, and <a class="el" href="a06768.html#l00444">RenderTriangle()</a>. +<p> +<div class="fragment"><pre>00239 { +00240 <span class="comment">//std::cout << "Entering, Lock=" << _Lock << std::endl; </span> +00241 <span class="keywordflow">if</span> (<a class="code" href="a02516.html#NLMISC_1_1CFastMutexe0">atomic_swap</a> (&_Lock)) +00242 { +00243 <span class="comment">// First test</span> +00244 <a class="code" href="a04558.html#a15">uint</a> i; +00245 <span class="keywordflow">for</span> (i = 0 ;; ++i) +00246 { +00247 <a class="code" href="a04558.html#a15">uint</a> wait_time = i + 6; +00248 +00249 <span class="comment">// Increment wait time with a log function</span> +00250 <span class="keywordflow">if</span> (wait_time > 27) +00251 wait_time = 27; +00252 +00253 <span class="comment">// Sleep</span> +00254 <span class="keywordflow">if</span> (wait_time <= 20) +00255 wait_time = 0; +00256 <span class="keywordflow">else</span> +00257 wait_time = 1 << (wait_time - 20); +00258 +00259 <span class="keywordflow">if</span> (!<a class="code" href="a02516.html#NLMISC_1_1CFastMutexe0">atomic_swap</a> (&_Lock)) +00260 <span class="keywordflow">break</span>; +00261 +00262 <span class="preprocessor">#ifdef NL_OS_WINDOWS</span> +00263 <span class="preprocessor"></span> Sleep (wait_time); +00264 <span class="preprocessor">#else</span> +00265 <span class="preprocessor"></span> <span class="comment">//std::cout << "Sleeping i=" << i << std::endl;</span> +00266 usleep( wait_time*1000 ); +00267 <span class="preprocessor">#endif</span> +00268 <span class="preprocessor"></span> } +00269 } +00270 } +</pre></div> </td> + </tr> +</table> +<a class="anchor" name="NLMISC_1_1CFastMutexa2" doxytag="NLMISC::CFastMutex::init" ></a><p> +<table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> + <tr> + <td class="mdRow"> + <table cellpadding="0" cellspacing="0" border="0"> + <tr> + <td class="md" nowrap valign="top"> void NLMISC::CFastMutex::init </td> + <td class="md" valign="top">( </td> + <td class="md" nowrap valign="top">void </td> + <td class="mdname1" valign="top" nowrap> </td> + <td class="md" valign="top"> ) </td> + <td class="md" nowrap> volatile<code> [inline]</code></td> + </tr> + + </table> + </td> + </tr> +</table> +<table cellspacing=5 cellpadding=0 border=0> + <tr> + <td> + + </td> + <td> + +<p> +Same as constructor, useful for init in a shared memory block. +<p> + +<p> +Definition at line <a class="el" href="a06088.html#l00202">202</a> of file <a class="el" href="a06088.html">mutex.h</a>. +<p> +References <a class="el" href="a06088.html#l00280">_Lock</a>. +<p> +<div class="fragment"><pre>00202 { <a class="code" href="a02516.html#NLMISC_1_1CFastMutexr0">_Lock</a> = 0; } +</pre></div> </td> + </tr> +</table> +<a class="anchor" name="NLMISC_1_1CFastMutexa3" doxytag="NLMISC::CFastMutex::leave" ></a><p> +<table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> + <tr> + <td class="mdRow"> + <table cellpadding="0" cellspacing="0" border="0"> + <tr> + <td class="md" nowrap valign="top"> __forceinline void NLMISC::CFastMutex::leave </td> + <td class="md" valign="top">( </td> + <td class="mdname1" valign="top" nowrap> </td> + <td class="md" valign="top"> ) </td> + <td class="md" nowrap> volatile<code> [inline]</code></td> + </tr> + + </table> + </td> + </tr> +</table> +<table cellspacing=5 cellpadding=0 border=0> + <tr> + <td> + + </td> + <td> + +<p> + +<p> +Definition at line <a class="el" href="a06088.html#l00273">273</a> of file <a class="el" href="a06088.html">mutex.h</a>. +<p> +References <a class="el" href="a06088.html#l00280">_Lock</a>. +<p> +Referenced by <a class="el" href="a05490.html#l00209">NLMISC::CBlockMemory< CNode >::__stl_alloc_changeEltSize()</a>, <a class="el" href="a05490.html#l00097">NLMISC::CBlockMemory< CNode >::allocate()</a>, <a class="el" href="a05490.html#l00147">NLMISC::CBlockMemory< CNode >::free()</a>, <a class="el" href="a05490.html#l00185">NLMISC::CBlockMemory< CNode >::purge()</a>, and <a class="el" href="a06768.html#l00444">RenderTriangle()</a>. +<p> +<div class="fragment"><pre>00274 { +00275 <a class="code" href="a02516.html#NLMISC_1_1CFastMutexr0">_Lock</a> = 0; +00276 <span class="comment">//std::cout << "Leave" << std::endl; </span> +00277 } +</pre></div> </td> + </tr> +</table> +<hr><h2>Field Documentation</h2> +<a class="anchor" name="NLMISC_1_1CFastMutexr0" doxytag="NLMISC::CFastMutex::_Lock" ></a><p> +<table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> + <tr> + <td class="mdRow"> + <table cellpadding="0" cellspacing="0" border="0"> + <tr> + <td class="md" nowrap valign="top"> volatile <a class="el" href="a04558.html#a11">uint32</a> <a class="el" href="a02516.html#NLMISC_1_1CFastMutexr0">NLMISC::CFastMutex::_Lock</a><code> [private]</code> + </table> + </td> + </tr> +</table> +<table cellspacing=5 cellpadding=0 border=0> + <tr> + <td> + + </td> + <td> + +<p> + +<p> +Definition at line <a class="el" href="a06088.html#l00280">280</a> of file <a class="el" href="a06088.html">mutex.h</a>. +<p> +Referenced by <a class="el" href="a06088.html#l00199">CFastMutex()</a>, <a class="el" href="a06088.html#l00238">enter()</a>, <a class="el" href="a06088.html#l00202">init()</a>, and <a class="el" href="a06088.html#l00273">leave()</a>. </td> + </tr> +</table> +<hr>The documentation for this class was generated from the following file:<ul> +<li><a class="el" href="a06088.html">mutex.h</a></ul> +<hr size="1"><address style="align: right;"><small>Generated on Tue Mar 16 13:12:31 2004 for NeL by +<a href="http://www.doxygen.org/index.html"> +<img src="doxygen.png" alt="doxygen" align="middle" border=0 > +</a>1.3.6 </small></address> +</body> +</html> |