mirror of
https://github.com/etlegacy/Update-Installer.git
synced 2024-11-26 05:41:28 +00:00
5360d05867
This saves the need to install Boost::Thread on each of the build systems.
517 lines
51 KiB
HTML
517 lines
51 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<title>TinyThread++: tinythread.h Source File</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
|
|
</head>
|
|
<body>
|
|
<!-- Generated by Doxygen 1.6.3 -->
|
|
<div class="navigation" id="top">
|
|
<div class="tabs">
|
|
<ul>
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
|
|
<li><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li class="current"><a href="files.html"><span>Files</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="tabs">
|
|
<ul>
|
|
<li><a href="files.html"><span>File List</span></a></li>
|
|
<li><a href="globals.html"><span>File Members</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<h1>tinythread.h</h1><a href="tinythread_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
|
|
<a name="l00002"></a>00002 <span class="comment">Copyright (c) 2010 Marcus Geelnard</span>
|
|
<a name="l00003"></a>00003 <span class="comment"></span>
|
|
<a name="l00004"></a>00004 <span class="comment">This software is provided 'as-is', without any express or implied</span>
|
|
<a name="l00005"></a>00005 <span class="comment">warranty. In no event will the authors be held liable for any damages</span>
|
|
<a name="l00006"></a>00006 <span class="comment">arising from the use of this software.</span>
|
|
<a name="l00007"></a>00007 <span class="comment"></span>
|
|
<a name="l00008"></a>00008 <span class="comment">Permission is granted to anyone to use this software for any purpose,</span>
|
|
<a name="l00009"></a>00009 <span class="comment">including commercial applications, and to alter it and redistribute it</span>
|
|
<a name="l00010"></a>00010 <span class="comment">freely, subject to the following restrictions:</span>
|
|
<a name="l00011"></a>00011 <span class="comment"></span>
|
|
<a name="l00012"></a>00012 <span class="comment"> 1. The origin of this software must not be misrepresented; you must not</span>
|
|
<a name="l00013"></a>00013 <span class="comment"> claim that you wrote the original software. If you use this software</span>
|
|
<a name="l00014"></a>00014 <span class="comment"> in a product, an acknowledgment in the product documentation would be</span>
|
|
<a name="l00015"></a>00015 <span class="comment"> appreciated but is not required.</span>
|
|
<a name="l00016"></a>00016 <span class="comment"></span>
|
|
<a name="l00017"></a>00017 <span class="comment"> 2. Altered source versions must be plainly marked as such, and must not be</span>
|
|
<a name="l00018"></a>00018 <span class="comment"> misrepresented as being the original software.</span>
|
|
<a name="l00019"></a>00019 <span class="comment"></span>
|
|
<a name="l00020"></a>00020 <span class="comment"> 3. This notice may not be removed or altered from any source</span>
|
|
<a name="l00021"></a>00021 <span class="comment"> distribution.</span>
|
|
<a name="l00022"></a>00022 <span class="comment">*/</span>
|
|
<a name="l00023"></a>00023
|
|
<a name="l00024"></a>00024 <span class="preprocessor">#ifndef _TINYTHREAD_H_</span>
|
|
<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#define _TINYTHREAD_H_</span>
|
|
<a name="l00026"></a>00026 <span class="preprocessor"></span>
|
|
<a name="l00057"></a>00057
|
|
<a name="l00058"></a>00058 <span class="comment">// Which platform are we on?</span>
|
|
<a name="l00059"></a>00059 <span class="preprocessor">#if !defined(_TTHREAD_PLATFORM_DEFINED_)</span>
|
|
<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor"> #if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)</span>
|
|
<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="preprocessor"> #define _TTHREAD_WIN32_</span>
|
|
<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor"> #else</span>
|
|
<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor"> #define _TTHREAD_POSIX_</span>
|
|
<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor"> #endif</span>
|
|
<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor"> #define _TTHREAD_PLATFORM_DEFINED_</span>
|
|
<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
|
|
<a name="l00067"></a>00067 <span class="preprocessor"></span>
|
|
<a name="l00068"></a>00068 <span class="comment">// Platform specific includes</span>
|
|
<a name="l00069"></a>00069 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00070"></a>00070 <span class="preprocessor"></span><span class="preprocessor"> #include <windows.h></span>
|
|
<a name="l00071"></a>00071 <span class="preprocessor">#else</span>
|
|
<a name="l00072"></a>00072 <span class="preprocessor"></span><span class="preprocessor"> #include <pthread.h></span>
|
|
<a name="l00073"></a>00073 <span class="preprocessor"> #include <signal.h></span>
|
|
<a name="l00074"></a>00074 <span class="preprocessor"> #include <sched.h></span>
|
|
<a name="l00075"></a>00075 <span class="preprocessor"> #include <unistd.h></span>
|
|
<a name="l00076"></a>00076 <span class="preprocessor">#endif</span>
|
|
<a name="l00077"></a>00077 <span class="preprocessor"></span>
|
|
<a name="l00078"></a>00078 <span class="comment">// Generic includes</span>
|
|
<a name="l00079"></a>00079 <span class="preprocessor">#include <ostream></span>
|
|
<a name="l00080"></a>00080
|
|
<a name="l00082"></a><a class="code" href="tinythread_8h.html#af1d2d7842598b143f8e0a54a9b6f5bec">00082</a> <span class="preprocessor">#define TINYTHREAD_VERSION_MAJOR 1</span>
|
|
<a name="l00083"></a>00083 <span class="preprocessor"></span>
|
|
<a name="l00084"></a><a class="code" href="tinythread_8h.html#a9248a2e6daaeb43e46bd632417cb4733">00084</a> <span class="preprocessor">#define TINYTHREAD_VERSION_MINOR 0</span>
|
|
<a name="l00085"></a>00085 <span class="preprocessor"></span>
|
|
<a name="l00086"></a><a class="code" href="tinythread_8h.html#a9a3d5a9159f22201a37dd59d82b1861f">00086</a> <span class="preprocessor">#define TINYTHREAD_VERSION (TINYTHREAD_VERSION_MAJOR * 100 + TINYTHREAD_VERSION_MINOR)</span>
|
|
<a name="l00087"></a>00087 <span class="preprocessor"></span>
|
|
<a name="l00088"></a>00088 <span class="comment">// Do we have a fully featured C++0x compiler?</span>
|
|
<a name="l00089"></a>00089 <span class="preprocessor">#if (__cplusplus > 199711L) || (defined(__STDCXX_VERSION__) && (__STDCXX_VERSION__ >= 201001L))</span>
|
|
<a name="l00090"></a>00090 <span class="preprocessor"></span><span class="preprocessor"> #define _TTHREAD_CPP0X_</span>
|
|
<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
|
|
<a name="l00092"></a>00092 <span class="preprocessor"></span>
|
|
<a name="l00093"></a>00093 <span class="comment">// ...at least partial C++0x?</span>
|
|
<a name="l00094"></a>00094 <span class="preprocessor">#if defined(_TTHREAD_CPP0X_) || defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(__GXX_EXPERIMENTAL_CPP0X__)</span>
|
|
<a name="l00095"></a>00095 <span class="preprocessor"></span><span class="preprocessor"> #define _TTHREAD_CPP0X_PARTIAL_</span>
|
|
<a name="l00096"></a>00096 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
|
|
<a name="l00097"></a>00097 <span class="preprocessor"></span>
|
|
<a name="l00098"></a>00098 <span class="comment">// Macro for disabling assignments of objects.</span>
|
|
<a name="l00099"></a>00099 <span class="preprocessor">#ifdef _TTHREAD_CPP0X_PARTIAL_</span>
|
|
<a name="l00100"></a>00100 <span class="preprocessor"></span><span class="preprocessor"> #define _TTHREAD_DISABLE_ASSIGNMENT(name) \</span>
|
|
<a name="l00101"></a>00101 <span class="preprocessor"> name(const name&) = delete; \</span>
|
|
<a name="l00102"></a>00102 <span class="preprocessor"> name& operator=(const name&) = delete;</span>
|
|
<a name="l00103"></a>00103 <span class="preprocessor"></span><span class="preprocessor">#else</span>
|
|
<a name="l00104"></a>00104 <span class="preprocessor"></span><span class="preprocessor"> #define _TTHREAD_DISABLE_ASSIGNMENT(name) \</span>
|
|
<a name="l00105"></a>00105 <span class="preprocessor"> name(const name&); \</span>
|
|
<a name="l00106"></a>00106 <span class="preprocessor"> name& operator=(const name&);</span>
|
|
<a name="l00107"></a>00107 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
|
|
<a name="l00108"></a>00108 <span class="preprocessor"></span>
|
|
<a name="l00129"></a>00129
|
|
<a name="l00130"></a>00130 <span class="preprocessor">#if !defined(_TTHREAD_CPP0X_) && !defined(thread_local)</span>
|
|
<a name="l00131"></a>00131 <span class="preprocessor"></span><span class="preprocessor"> #if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_CC) || defined(__IBMCPP__)</span>
|
|
<a name="l00132"></a>00132 <span class="preprocessor"></span><span class="preprocessor"> #define thread_local __thread</span>
|
|
<a name="l00133"></a>00133 <span class="preprocessor"></span><span class="preprocessor"> #else</span>
|
|
<a name="l00134"></a><a class="code" href="tinythread_8h.html#ad4d9b405bcbffaf0d4dae6166c18aa1e">00134</a> <span class="preprocessor"></span><span class="preprocessor"> #define thread_local __declspec(thread)</span>
|
|
<a name="l00135"></a>00135 <span class="preprocessor"></span><span class="preprocessor"> #endif</span>
|
|
<a name="l00136"></a>00136 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
|
|
<a name="l00137"></a>00137 <span class="preprocessor"></span>
|
|
<a name="l00138"></a>00138
|
|
<a name="l00143"></a>00143 <span class="keyword">namespace </span>tthread {
|
|
<a name="l00144"></a>00144
|
|
<a name="l00151"></a><a class="code" href="classtthread_1_1mutex.html">00151</a> <span class="keyword">class </span><a class="code" href="classtthread_1_1mutex.html" title="Mutex class.">mutex</a> {
|
|
<a name="l00152"></a>00152 <span class="keyword">public</span>:
|
|
<a name="l00154"></a><a class="code" href="classtthread_1_1mutex.html#aef42e2bd0ea2ffa8ce1cdc7e5d183910">00154</a> <a class="code" href="classtthread_1_1mutex.html#aef42e2bd0ea2ffa8ce1cdc7e5d183910" title="Constructor.">mutex</a>()
|
|
<a name="l00155"></a>00155 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00156"></a>00156 <span class="preprocessor"></span> : mAlreadyLocked(<span class="keyword">false</span>)
|
|
<a name="l00157"></a>00157 <span class="preprocessor">#endif</span>
|
|
<a name="l00158"></a>00158 <span class="preprocessor"></span> {
|
|
<a name="l00159"></a>00159 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00160"></a>00160 <span class="preprocessor"></span> InitializeCriticalSection(&mHandle);
|
|
<a name="l00161"></a>00161 <span class="preprocessor">#else</span>
|
|
<a name="l00162"></a>00162 <span class="preprocessor"></span> pthread_mutex_init(&mHandle, NULL);
|
|
<a name="l00163"></a>00163 <span class="preprocessor">#endif</span>
|
|
<a name="l00164"></a>00164 <span class="preprocessor"></span> }
|
|
<a name="l00165"></a>00165
|
|
<a name="l00167"></a><a class="code" href="classtthread_1_1mutex.html#a3ab9328c3addeb57045f45910b10a1cf">00167</a> <a class="code" href="classtthread_1_1mutex.html#a3ab9328c3addeb57045f45910b10a1cf" title="Destructor.">~mutex</a>()
|
|
<a name="l00168"></a>00168 {
|
|
<a name="l00169"></a>00169 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00170"></a>00170 <span class="preprocessor"></span> DeleteCriticalSection(&mHandle);
|
|
<a name="l00171"></a>00171 <span class="preprocessor">#else</span>
|
|
<a name="l00172"></a>00172 <span class="preprocessor"></span> pthread_mutex_destroy(&mHandle);
|
|
<a name="l00173"></a>00173 <span class="preprocessor">#endif</span>
|
|
<a name="l00174"></a>00174 <span class="preprocessor"></span> }
|
|
<a name="l00175"></a>00175
|
|
<a name="l00180"></a><a class="code" href="classtthread_1_1mutex.html#aa81aed607133209dade63a226818224d">00180</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classtthread_1_1mutex.html#aa81aed607133209dade63a226818224d" title="Lock the mutex.">lock</a>()
|
|
<a name="l00181"></a>00181 {
|
|
<a name="l00182"></a>00182 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00183"></a>00183 <span class="preprocessor"></span> EnterCriticalSection(&mHandle);
|
|
<a name="l00184"></a>00184 <span class="keywordflow">while</span>(mAlreadyLocked) Sleep(1000); <span class="comment">// Simulate deadlock...</span>
|
|
<a name="l00185"></a>00185 mAlreadyLocked = <span class="keyword">true</span>;
|
|
<a name="l00186"></a>00186 <span class="preprocessor">#else</span>
|
|
<a name="l00187"></a>00187 <span class="preprocessor"></span> pthread_mutex_lock(&mHandle);
|
|
<a name="l00188"></a>00188 <span class="preprocessor">#endif</span>
|
|
<a name="l00189"></a>00189 <span class="preprocessor"></span> }
|
|
<a name="l00190"></a>00190
|
|
<a name="l00196"></a><a class="code" href="classtthread_1_1mutex.html#aa24a64f788f142df670c3abc809d32b6">00196</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classtthread_1_1mutex.html#aa24a64f788f142df670c3abc809d32b6" title="Try to lock the mutex.">try_lock</a>()
|
|
<a name="l00197"></a>00197 {
|
|
<a name="l00198"></a>00198 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00199"></a>00199 <span class="preprocessor"></span> <span class="keywordtype">bool</span> ret = (TryEnterCriticalSection(&mHandle) ? <span class="keyword">true</span> : <span class="keyword">false</span>);
|
|
<a name="l00200"></a>00200 <span class="keywordflow">if</span>(ret && mAlreadyLocked)
|
|
<a name="l00201"></a>00201 {
|
|
<a name="l00202"></a>00202 LeaveCriticalSection(&mHandle);
|
|
<a name="l00203"></a>00203 ret = <span class="keyword">false</span>;
|
|
<a name="l00204"></a>00204 }
|
|
<a name="l00205"></a>00205 <span class="keywordflow">return</span> ret;
|
|
<a name="l00206"></a>00206 <span class="preprocessor">#else</span>
|
|
<a name="l00207"></a>00207 <span class="preprocessor"></span> <span class="keywordflow">return</span> (pthread_mutex_trylock(&mHandle) == 0) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
|
|
<a name="l00208"></a>00208 <span class="preprocessor">#endif</span>
|
|
<a name="l00209"></a>00209 <span class="preprocessor"></span> }
|
|
<a name="l00210"></a>00210
|
|
<a name="l00214"></a><a class="code" href="classtthread_1_1mutex.html#a9278be8203e1c42e2619179882ae4403">00214</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classtthread_1_1mutex.html#a9278be8203e1c42e2619179882ae4403" title="Unlock the mutex.">unlock</a>()
|
|
<a name="l00215"></a>00215 {
|
|
<a name="l00216"></a>00216 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00217"></a>00217 <span class="preprocessor"></span> mAlreadyLocked = <span class="keyword">false</span>;
|
|
<a name="l00218"></a>00218 LeaveCriticalSection(&mHandle);
|
|
<a name="l00219"></a>00219 <span class="preprocessor">#else</span>
|
|
<a name="l00220"></a>00220 <span class="preprocessor"></span> pthread_mutex_unlock(&mHandle);
|
|
<a name="l00221"></a>00221 <span class="preprocessor">#endif</span>
|
|
<a name="l00222"></a>00222 <span class="preprocessor"></span> }
|
|
<a name="l00223"></a>00223
|
|
<a name="l00224"></a>00224 _TTHREAD_DISABLE_ASSIGNMENT(<a class="code" href="classtthread_1_1mutex.html" title="Mutex class.">mutex</a>)
|
|
<a name="l00225"></a>00225
|
|
<a name="l00226"></a>00226 private:
|
|
<a name="l00227"></a>00227 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00228"></a>00228 <span class="preprocessor"></span> CRITICAL_SECTION mHandle;
|
|
<a name="l00229"></a>00229 <span class="keywordtype">bool</span> mAlreadyLocked;
|
|
<a name="l00230"></a>00230 <span class="preprocessor">#else</span>
|
|
<a name="l00231"></a>00231 <span class="preprocessor"></span> pthread_mutex_t mHandle;
|
|
<a name="l00232"></a>00232 <span class="preprocessor">#endif</span>
|
|
<a name="l00233"></a>00233 <span class="preprocessor"></span>
|
|
<a name="l00234"></a>00234 <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classtthread_1_1condition__variable.html" title="Condition variable class.">condition_variable</a>;
|
|
<a name="l00235"></a>00235 };
|
|
<a name="l00236"></a>00236
|
|
<a name="l00243"></a><a class="code" href="classtthread_1_1recursive__mutex.html">00243</a> <span class="keyword">class </span><a class="code" href="classtthread_1_1recursive__mutex.html" title="Recursive mutex class.">recursive_mutex</a> {
|
|
<a name="l00244"></a>00244 <span class="keyword">public</span>:
|
|
<a name="l00246"></a><a class="code" href="classtthread_1_1recursive__mutex.html#a612d33a8905a3de216a8be0467538ede">00246</a> <a class="code" href="classtthread_1_1recursive__mutex.html#a612d33a8905a3de216a8be0467538ede" title="Constructor.">recursive_mutex</a>()
|
|
<a name="l00247"></a>00247 {
|
|
<a name="l00248"></a>00248 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00249"></a>00249 <span class="preprocessor"></span> InitializeCriticalSection(&mHandle);
|
|
<a name="l00250"></a>00250 <span class="preprocessor">#else</span>
|
|
<a name="l00251"></a>00251 <span class="preprocessor"></span> pthread_mutexattr_t attr;
|
|
<a name="l00252"></a>00252 pthread_mutexattr_init(&attr);
|
|
<a name="l00253"></a>00253 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
|
<a name="l00254"></a>00254 pthread_mutex_init(&mHandle, &attr);
|
|
<a name="l00255"></a>00255 <span class="preprocessor">#endif</span>
|
|
<a name="l00256"></a>00256 <span class="preprocessor"></span> }
|
|
<a name="l00257"></a>00257
|
|
<a name="l00259"></a><a class="code" href="classtthread_1_1recursive__mutex.html#a571b16a7b52c4d1fb0bdb5ff0482c100">00259</a> <a class="code" href="classtthread_1_1recursive__mutex.html#a571b16a7b52c4d1fb0bdb5ff0482c100" title="Destructor.">~recursive_mutex</a>()
|
|
<a name="l00260"></a>00260 {
|
|
<a name="l00261"></a>00261 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00262"></a>00262 <span class="preprocessor"></span> DeleteCriticalSection(&mHandle);
|
|
<a name="l00263"></a>00263 <span class="preprocessor">#else</span>
|
|
<a name="l00264"></a>00264 <span class="preprocessor"></span> pthread_mutex_destroy(&mHandle);
|
|
<a name="l00265"></a>00265 <span class="preprocessor">#endif</span>
|
|
<a name="l00266"></a>00266 <span class="preprocessor"></span> }
|
|
<a name="l00267"></a>00267
|
|
<a name="l00272"></a><a class="code" href="classtthread_1_1recursive__mutex.html#aa81aed607133209dade63a226818224d">00272</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classtthread_1_1recursive__mutex.html#aa81aed607133209dade63a226818224d" title="Lock the mutex.">lock</a>()
|
|
<a name="l00273"></a>00273 {
|
|
<a name="l00274"></a>00274 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00275"></a>00275 <span class="preprocessor"></span> EnterCriticalSection(&mHandle);
|
|
<a name="l00276"></a>00276 <span class="preprocessor">#else</span>
|
|
<a name="l00277"></a>00277 <span class="preprocessor"></span> pthread_mutex_lock(&mHandle);
|
|
<a name="l00278"></a>00278 <span class="preprocessor">#endif</span>
|
|
<a name="l00279"></a>00279 <span class="preprocessor"></span> }
|
|
<a name="l00280"></a>00280
|
|
<a name="l00286"></a><a class="code" href="classtthread_1_1recursive__mutex.html#aa24a64f788f142df670c3abc809d32b6">00286</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classtthread_1_1recursive__mutex.html#aa24a64f788f142df670c3abc809d32b6" title="Try to lock the mutex.">try_lock</a>()
|
|
<a name="l00287"></a>00287 {
|
|
<a name="l00288"></a>00288 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00289"></a>00289 <span class="preprocessor"></span> <span class="keywordflow">return</span> TryEnterCriticalSection(&mHandle) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
|
|
<a name="l00290"></a>00290 <span class="preprocessor">#else</span>
|
|
<a name="l00291"></a>00291 <span class="preprocessor"></span> <span class="keywordflow">return</span> (pthread_mutex_trylock(&mHandle) == 0) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
|
|
<a name="l00292"></a>00292 <span class="preprocessor">#endif</span>
|
|
<a name="l00293"></a>00293 <span class="preprocessor"></span> }
|
|
<a name="l00294"></a>00294
|
|
<a name="l00298"></a><a class="code" href="classtthread_1_1recursive__mutex.html#a9278be8203e1c42e2619179882ae4403">00298</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classtthread_1_1recursive__mutex.html#a9278be8203e1c42e2619179882ae4403" title="Unlock the mutex.">unlock</a>()
|
|
<a name="l00299"></a>00299 {
|
|
<a name="l00300"></a>00300 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00301"></a>00301 <span class="preprocessor"></span> LeaveCriticalSection(&mHandle);
|
|
<a name="l00302"></a>00302 <span class="preprocessor">#else</span>
|
|
<a name="l00303"></a>00303 <span class="preprocessor"></span> pthread_mutex_unlock(&mHandle);
|
|
<a name="l00304"></a>00304 <span class="preprocessor">#endif</span>
|
|
<a name="l00305"></a>00305 <span class="preprocessor"></span> }
|
|
<a name="l00306"></a>00306
|
|
<a name="l00307"></a>00307 _TTHREAD_DISABLE_ASSIGNMENT(<a class="code" href="classtthread_1_1recursive__mutex.html" title="Recursive mutex class.">recursive_mutex</a>)
|
|
<a name="l00308"></a>00308
|
|
<a name="l00309"></a>00309 private:
|
|
<a name="l00310"></a>00310 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00311"></a>00311 <span class="preprocessor"></span> CRITICAL_SECTION mHandle;
|
|
<a name="l00312"></a>00312 <span class="preprocessor">#else</span>
|
|
<a name="l00313"></a>00313 <span class="preprocessor"></span> pthread_mutex_t mHandle;
|
|
<a name="l00314"></a>00314 <span class="preprocessor">#endif</span>
|
|
<a name="l00315"></a>00315 <span class="preprocessor"></span>
|
|
<a name="l00316"></a>00316 <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classtthread_1_1condition__variable.html" title="Condition variable class.">condition_variable</a>;
|
|
<a name="l00317"></a>00317 };
|
|
<a name="l00318"></a>00318
|
|
<a name="l00333"></a>00333
|
|
<a name="l00334"></a>00334 <span class="keyword">template</span> <<span class="keyword">class</span> T>
|
|
<a name="l00335"></a><a class="code" href="classtthread_1_1lock__guard.html">00335</a> <span class="keyword">class </span><a class="code" href="classtthread_1_1lock__guard.html" title="Lock guard class.">lock_guard</a> {
|
|
<a name="l00336"></a>00336 <span class="keyword">public</span>:
|
|
<a name="l00337"></a>00337 <span class="keyword">typedef</span> T mutex_type;
|
|
<a name="l00338"></a>00338
|
|
<a name="l00339"></a>00339 <a class="code" href="classtthread_1_1lock__guard.html" title="Lock guard class.">lock_guard</a>() : mMutex(0) {}
|
|
<a name="l00340"></a>00340
|
|
<a name="l00342"></a><a class="code" href="classtthread_1_1lock__guard.html#a2c5fd14427acb035def5201e4cfd4540">00342</a> <span class="keyword">explicit</span> <a class="code" href="classtthread_1_1lock__guard.html" title="Lock guard class.">lock_guard</a>(mutex_type &aMutex)
|
|
<a name="l00343"></a>00343 {
|
|
<a name="l00344"></a>00344 mMutex = &aMutex;
|
|
<a name="l00345"></a>00345 mMutex->lock();
|
|
<a name="l00346"></a>00346 }
|
|
<a name="l00347"></a>00347
|
|
<a name="l00349"></a><a class="code" href="classtthread_1_1lock__guard.html#aa54999fb933a139807d39ed05e97aa6d">00349</a> <a class="code" href="classtthread_1_1lock__guard.html#aa54999fb933a139807d39ed05e97aa6d" title="The destructor unlocks the mutex.">~lock_guard</a>()
|
|
<a name="l00350"></a>00350 {
|
|
<a name="l00351"></a>00351 <span class="keywordflow">if</span>(mMutex)
|
|
<a name="l00352"></a>00352 mMutex->unlock();
|
|
<a name="l00353"></a>00353 }
|
|
<a name="l00354"></a>00354
|
|
<a name="l00355"></a>00355 <span class="keyword">private</span>:
|
|
<a name="l00356"></a>00356 mutex_type * mMutex;
|
|
<a name="l00357"></a>00357 };
|
|
<a name="l00358"></a>00358
|
|
<a name="l00384"></a><a class="code" href="classtthread_1_1condition__variable.html">00384</a> <span class="keyword">class </span><a class="code" href="classtthread_1_1condition__variable.html" title="Condition variable class.">condition_variable</a> {
|
|
<a name="l00385"></a>00385 <span class="keyword">public</span>:
|
|
<a name="l00387"></a>00387 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00388"></a>00388 <span class="preprocessor"></span> <a class="code" href="classtthread_1_1condition__variable.html#a9e62a1d1145c820a02469a48099fdfa9" title="Constructor.">condition_variable</a>();
|
|
<a name="l00389"></a>00389 <span class="preprocessor">#else</span>
|
|
<a name="l00390"></a><a class="code" href="classtthread_1_1condition__variable.html#a9e62a1d1145c820a02469a48099fdfa9">00390</a> <span class="preprocessor"></span> <a class="code" href="classtthread_1_1condition__variable.html#a9e62a1d1145c820a02469a48099fdfa9" title="Constructor.">condition_variable</a>()
|
|
<a name="l00391"></a>00391 {
|
|
<a name="l00392"></a>00392 pthread_cond_init(&mHandle, NULL);
|
|
<a name="l00393"></a>00393 }
|
|
<a name="l00394"></a>00394 <span class="preprocessor">#endif</span>
|
|
<a name="l00395"></a>00395 <span class="preprocessor"></span>
|
|
<a name="l00397"></a>00397 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00398"></a>00398 <span class="preprocessor"></span> <a class="code" href="classtthread_1_1condition__variable.html#a58df09046f5006d4170ae92717f1e50b" title="Destructor.">~condition_variable</a>();
|
|
<a name="l00399"></a>00399 <span class="preprocessor">#else</span>
|
|
<a name="l00400"></a><a class="code" href="classtthread_1_1condition__variable.html#a58df09046f5006d4170ae92717f1e50b">00400</a> <span class="preprocessor"></span> <a class="code" href="classtthread_1_1condition__variable.html#a58df09046f5006d4170ae92717f1e50b" title="Destructor.">~condition_variable</a>()
|
|
<a name="l00401"></a>00401 {
|
|
<a name="l00402"></a>00402 pthread_cond_destroy(&mHandle);
|
|
<a name="l00403"></a>00403 }
|
|
<a name="l00404"></a>00404 <span class="preprocessor">#endif</span>
|
|
<a name="l00405"></a>00405 <span class="preprocessor"></span>
|
|
<a name="l00411"></a>00411 <span class="keyword">template</span> <<span class="keyword">class</span> _mutexT>
|
|
<a name="l00412"></a><a class="code" href="classtthread_1_1condition__variable.html#a4d877d804385bde4aacf2156e86faede">00412</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classtthread_1_1condition__variable.html#a4d877d804385bde4aacf2156e86faede" title="Wait for the condition.">wait</a>(_mutexT &aMutex)
|
|
<a name="l00413"></a>00413 {
|
|
<a name="l00414"></a>00414 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00415"></a>00415 <span class="preprocessor"></span> <span class="comment">// Increment number of waiters</span>
|
|
<a name="l00416"></a>00416 EnterCriticalSection(&mWaitersCountLock);
|
|
<a name="l00417"></a>00417 ++ mWaitersCount;
|
|
<a name="l00418"></a>00418 LeaveCriticalSection(&mWaitersCountLock);
|
|
<a name="l00419"></a>00419
|
|
<a name="l00420"></a>00420 <span class="comment">// Release the mutex while waiting for the condition (will decrease</span>
|
|
<a name="l00421"></a>00421 <span class="comment">// the number of waiters when done)...</span>
|
|
<a name="l00422"></a>00422 aMutex.unlock();
|
|
<a name="l00423"></a>00423 _wait();
|
|
<a name="l00424"></a>00424 aMutex.lock();
|
|
<a name="l00425"></a>00425 <span class="preprocessor">#else</span>
|
|
<a name="l00426"></a>00426 <span class="preprocessor"></span> pthread_cond_wait(&mHandle, &aMutex.mHandle);
|
|
<a name="l00427"></a>00427 <span class="preprocessor">#endif</span>
|
|
<a name="l00428"></a>00428 <span class="preprocessor"></span> }
|
|
<a name="l00429"></a>00429
|
|
<a name="l00435"></a>00435 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00436"></a>00436 <span class="preprocessor"></span> <span class="keywordtype">void</span> <a class="code" href="classtthread_1_1condition__variable.html#a84c2ec0dd971c593883198a323eeb394" title="Notify one thread that is waiting for the condition.">notify_one</a>();
|
|
<a name="l00437"></a>00437 <span class="preprocessor">#else</span>
|
|
<a name="l00438"></a><a class="code" href="classtthread_1_1condition__variable.html#a84c2ec0dd971c593883198a323eeb394">00438</a> <span class="preprocessor"></span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classtthread_1_1condition__variable.html#a84c2ec0dd971c593883198a323eeb394" title="Notify one thread that is waiting for the condition.">notify_one</a>()
|
|
<a name="l00439"></a>00439 {
|
|
<a name="l00440"></a>00440 pthread_cond_signal(&mHandle);
|
|
<a name="l00441"></a>00441 }
|
|
<a name="l00442"></a>00442 <span class="preprocessor">#endif</span>
|
|
<a name="l00443"></a>00443 <span class="preprocessor"></span>
|
|
<a name="l00449"></a>00449 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00450"></a>00450 <span class="preprocessor"></span> <span class="keywordtype">void</span> <a class="code" href="classtthread_1_1condition__variable.html#ad35a04e61229c15c5211ebff00089326" title="Notify all threads that are waiting for the condition.">notify_all</a>();
|
|
<a name="l00451"></a>00451 <span class="preprocessor">#else</span>
|
|
<a name="l00452"></a><a class="code" href="classtthread_1_1condition__variable.html#ad35a04e61229c15c5211ebff00089326">00452</a> <span class="preprocessor"></span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classtthread_1_1condition__variable.html#ad35a04e61229c15c5211ebff00089326" title="Notify all threads that are waiting for the condition.">notify_all</a>()
|
|
<a name="l00453"></a>00453 {
|
|
<a name="l00454"></a>00454 pthread_cond_broadcast(&mHandle);
|
|
<a name="l00455"></a>00455 }
|
|
<a name="l00456"></a>00456 <span class="preprocessor">#endif</span>
|
|
<a name="l00457"></a>00457 <span class="preprocessor"></span>
|
|
<a name="l00458"></a>00458 _TTHREAD_DISABLE_ASSIGNMENT(<a class="code" href="classtthread_1_1condition__variable.html" title="Condition variable class.">condition_variable</a>)
|
|
<a name="l00459"></a>00459
|
|
<a name="l00460"></a>00460 private:
|
|
<a name="l00461"></a>00461 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00462"></a>00462 <span class="preprocessor"></span> <span class="keywordtype">void</span> _wait();
|
|
<a name="l00463"></a>00463 HANDLE mEvents[2];
|
|
<a name="l00464"></a>00464 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> mWaitersCount;
|
|
<a name="l00465"></a>00465 CRITICAL_SECTION mWaitersCountLock;
|
|
<a name="l00466"></a>00466 <span class="preprocessor">#else</span>
|
|
<a name="l00467"></a>00467 <span class="preprocessor"></span> pthread_cond_t mHandle;
|
|
<a name="l00468"></a>00468 <span class="preprocessor">#endif</span>
|
|
<a name="l00469"></a>00469 <span class="preprocessor"></span>};
|
|
<a name="l00470"></a>00470
|
|
<a name="l00471"></a>00471
|
|
<a name="l00473"></a><a class="code" href="classtthread_1_1thread.html">00473</a> <span class="keyword">class </span><a class="code" href="classtthread_1_1thread.html" title="Thread class.">thread</a> {
|
|
<a name="l00474"></a>00474 <span class="keyword">public</span>:
|
|
<a name="l00475"></a>00475 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00476"></a>00476 <span class="preprocessor"></span> <span class="keyword">typedef</span> HANDLE native_handle_type;
|
|
<a name="l00477"></a>00477 <span class="preprocessor">#else</span>
|
|
<a name="l00478"></a>00478 <span class="preprocessor"></span> <span class="keyword">typedef</span> pthread_t native_handle_type;
|
|
<a name="l00479"></a>00479 <span class="preprocessor">#endif</span>
|
|
<a name="l00480"></a>00480 <span class="preprocessor"></span>
|
|
<a name="l00481"></a>00481 <span class="keyword">class </span><a class="code" href="classtthread_1_1thread_1_1id.html" title="Thread ID.">id</a>;
|
|
<a name="l00482"></a>00482
|
|
<a name="l00486"></a><a class="code" href="classtthread_1_1thread.html#a1816c2a63c2941090f9a24e5a62efea1">00486</a> <a class="code" href="classtthread_1_1thread.html#a1816c2a63c2941090f9a24e5a62efea1" title="Default constructor.">thread</a>() : mHandle(0), mNotAThread(true)
|
|
<a name="l00487"></a>00487 #if defined(_TTHREAD_WIN32_)
|
|
<a name="l00488"></a>00488 , mWin32ThreadID(0)
|
|
<a name="l00489"></a>00489 #endif
|
|
<a name="l00490"></a>00490 {}
|
|
<a name="l00491"></a>00491
|
|
<a name="l00500"></a>00500 <a class="code" href="classtthread_1_1thread.html#a1816c2a63c2941090f9a24e5a62efea1" title="Default constructor.">thread</a>(<span class="keywordtype">void</span> (*aFunction)(<span class="keywordtype">void</span> *), <span class="keywordtype">void</span> * aArg);
|
|
<a name="l00501"></a>00501
|
|
<a name="l00506"></a>00506 <a class="code" href="classtthread_1_1thread.html#a626c04c85c7e2b10215bc4a35062f177" title="Destructor.">~thread</a>();
|
|
<a name="l00507"></a>00507
|
|
<a name="l00509"></a>00509 <span class="keywordtype">void</span> <a class="code" href="classtthread_1_1thread.html#a6c7abfff648dad193674fc432ad4840d" title="Wait for the thread to finish (join execution flows).">join</a>();
|
|
<a name="l00510"></a>00510
|
|
<a name="l00513"></a>00513 <span class="keywordtype">bool</span> <a class="code" href="classtthread_1_1thread.html#a5f02386ef3b6ef614321b6ec3606b242" title="Check if the thread is joinable.">joinable</a>() <span class="keyword">const</span>;
|
|
<a name="l00514"></a>00514
|
|
<a name="l00516"></a>00516 <span class="keywordtype">id</span> <a class="code" href="classtthread_1_1thread.html#afb4f4110b330d27774c16baec4f7d4f5" title="Return the thread ID of a thread object.">get_id</a>() <span class="keyword">const</span>;
|
|
<a name="l00517"></a>00517
|
|
<a name="l00521"></a><a class="code" href="classtthread_1_1thread.html#ac9ba019ced75a29c52c41aff4e1ca20e">00521</a> <span class="keyword">inline</span> native_handle_type <a class="code" href="classtthread_1_1thread.html#ac9ba019ced75a29c52c41aff4e1ca20e" title="Get the native handle for this thread.">native_handle</a>()
|
|
<a name="l00522"></a>00522 {
|
|
<a name="l00523"></a>00523 <span class="keywordflow">return</span> mHandle;
|
|
<a name="l00524"></a>00524 }
|
|
<a name="l00525"></a>00525
|
|
<a name="l00531"></a>00531 <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <a class="code" href="classtthread_1_1thread.html#a3b04fb20012111681e37dfe63f105f6d" title="Determine the number of threads which can possibly execute concurrently.">hardware_concurrency</a>();
|
|
<a name="l00532"></a>00532
|
|
<a name="l00533"></a>00533 _TTHREAD_DISABLE_ASSIGNMENT(<a class="code" href="classtthread_1_1thread.html" title="Thread class.">thread</a>)
|
|
<a name="l00534"></a>00534
|
|
<a name="l00535"></a>00535 private:
|
|
<a name="l00536"></a>00536 native_handle_type mHandle;
|
|
<a name="l00537"></a>00537 mutable <a class="code" href="classtthread_1_1mutex.html" title="Mutex class.">mutex</a> mDataMutex;
|
|
<a name="l00538"></a>00538 <span class="keywordtype">bool</span> mNotAThread;
|
|
<a name="l00539"></a>00539 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00540"></a>00540 <span class="preprocessor"></span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> mWin32ThreadID;
|
|
<a name="l00541"></a>00541 <span class="preprocessor">#endif</span>
|
|
<a name="l00542"></a>00542 <span class="preprocessor"></span>
|
|
<a name="l00543"></a>00543 <span class="comment">// This is the internal thread wrapper function.</span>
|
|
<a name="l00544"></a>00544 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00545"></a>00545 <span class="preprocessor"></span> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> WINAPI wrapper_function(<span class="keywordtype">void</span> * aArg);
|
|
<a name="l00546"></a>00546 <span class="preprocessor">#else</span>
|
|
<a name="l00547"></a>00547 <span class="preprocessor"></span> <span class="keyword">static</span> <span class="keywordtype">void</span> * wrapper_function(<span class="keywordtype">void</span> * aArg);
|
|
<a name="l00548"></a>00548 <span class="preprocessor">#endif</span>
|
|
<a name="l00549"></a>00549 <span class="preprocessor"></span>};
|
|
<a name="l00550"></a>00550
|
|
<a name="l00554"></a><a class="code" href="classtthread_1_1thread_1_1id.html">00554</a> <span class="keyword">class </span><a class="code" href="classtthread_1_1thread_1_1id.html" title="Thread ID.">thread::id</a> {
|
|
<a name="l00555"></a>00555 <span class="keyword">public</span>:
|
|
<a name="l00559"></a><a class="code" href="classtthread_1_1thread_1_1id.html#a087060b582403885d08e89ad894ecc5d">00559</a> <a class="code" href="classtthread_1_1thread_1_1id.html#a087060b582403885d08e89ad894ecc5d" title="Default constructor.">id</a>() : mId(0) {};
|
|
<a name="l00560"></a>00560
|
|
<a name="l00561"></a>00561 <a class="code" href="classtthread_1_1thread_1_1id.html#a087060b582403885d08e89ad894ecc5d" title="Default constructor.">id</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="keywordtype">int</span> aId) : mId(aId) {};
|
|
<a name="l00562"></a>00562
|
|
<a name="l00563"></a>00563 <a class="code" href="classtthread_1_1thread_1_1id.html#a087060b582403885d08e89ad894ecc5d" title="Default constructor.">id</a>(<span class="keyword">const</span> <span class="keywordtype">id</span>& aId) : mId(aId.mId) {};
|
|
<a name="l00564"></a>00564
|
|
<a name="l00565"></a>00565 <span class="keyword">inline</span> <span class="keywordtype">id</span> & operator=(<span class="keyword">const</span> <span class="keywordtype">id</span> &aId)
|
|
<a name="l00566"></a>00566 {
|
|
<a name="l00567"></a>00567 mId = aId.mId;
|
|
<a name="l00568"></a>00568 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
|
|
<a name="l00569"></a>00569 }
|
|
<a name="l00570"></a>00570
|
|
<a name="l00571"></a>00571 <span class="keyword">inline</span> <span class="keyword">friend</span> <span class="keywordtype">bool</span> operator==(<span class="keyword">const</span> <span class="keywordtype">id</span> &aId1, <span class="keyword">const</span> <span class="keywordtype">id</span> &aId2)
|
|
<a name="l00572"></a>00572 {
|
|
<a name="l00573"></a>00573 <span class="keywordflow">return</span> (aId1.mId == aId2.mId);
|
|
<a name="l00574"></a>00574 }
|
|
<a name="l00575"></a>00575
|
|
<a name="l00576"></a>00576 <span class="keyword">inline</span> <span class="keyword">friend</span> <span class="keywordtype">bool</span> operator!=(<span class="keyword">const</span> <span class="keywordtype">id</span> &aId1, <span class="keyword">const</span> <span class="keywordtype">id</span> &aId2)
|
|
<a name="l00577"></a>00577 {
|
|
<a name="l00578"></a>00578 <span class="keywordflow">return</span> (aId1.mId != aId2.mId);
|
|
<a name="l00579"></a>00579 }
|
|
<a name="l00580"></a>00580
|
|
<a name="l00581"></a>00581 <span class="keyword">inline</span> <span class="keyword">friend</span> <span class="keywordtype">bool</span> operator<=(<span class="keyword">const</span> <span class="keywordtype">id</span> &aId1, <span class="keyword">const</span> <span class="keywordtype">id</span> &aId2)
|
|
<a name="l00582"></a>00582 {
|
|
<a name="l00583"></a>00583 <span class="keywordflow">return</span> (aId1.mId <= aId2.mId);
|
|
<a name="l00584"></a>00584 }
|
|
<a name="l00585"></a>00585
|
|
<a name="l00586"></a>00586 <span class="keyword">inline</span> <span class="keyword">friend</span> <span class="keywordtype">bool</span> operator<(<span class="keyword">const</span> <span class="keywordtype">id</span> &aId1, <span class="keyword">const</span> <span class="keywordtype">id</span> &aId2)
|
|
<a name="l00587"></a>00587 {
|
|
<a name="l00588"></a>00588 <span class="keywordflow">return</span> (aId1.mId < aId2.mId);
|
|
<a name="l00589"></a>00589 }
|
|
<a name="l00590"></a>00590
|
|
<a name="l00591"></a>00591 <span class="keyword">inline</span> <span class="keyword">friend</span> <span class="keywordtype">bool</span> operator>=(<span class="keyword">const</span> <span class="keywordtype">id</span> &aId1, <span class="keyword">const</span> <span class="keywordtype">id</span> &aId2)
|
|
<a name="l00592"></a>00592 {
|
|
<a name="l00593"></a>00593 <span class="keywordflow">return</span> (aId1.mId >= aId2.mId);
|
|
<a name="l00594"></a>00594 }
|
|
<a name="l00595"></a>00595
|
|
<a name="l00596"></a>00596 <span class="keyword">inline</span> <span class="keyword">friend</span> <span class="keywordtype">bool</span> operator>(<span class="keyword">const</span> <span class="keywordtype">id</span> &aId1, <span class="keyword">const</span> <span class="keywordtype">id</span> &aId2)
|
|
<a name="l00597"></a>00597 {
|
|
<a name="l00598"></a>00598 <span class="keywordflow">return</span> (aId1.mId > aId2.mId);
|
|
<a name="l00599"></a>00599 }
|
|
<a name="l00600"></a>00600
|
|
<a name="l00601"></a>00601 <span class="keyword">inline</span> <span class="keyword">friend</span> std::ostream& operator <<(std::ostream &os, <span class="keyword">const</span> <span class="keywordtype">id</span> &obj)
|
|
<a name="l00602"></a>00602 {
|
|
<a name="l00603"></a>00603 os << obj.mId;
|
|
<a name="l00604"></a>00604 <span class="keywordflow">return</span> os;
|
|
<a name="l00605"></a>00605 }
|
|
<a name="l00606"></a>00606
|
|
<a name="l00607"></a>00607 <span class="keyword">private</span>:
|
|
<a name="l00608"></a>00608 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="keywordtype">int</span> mId;
|
|
<a name="l00609"></a>00609 };
|
|
<a name="l00610"></a>00610
|
|
<a name="l00611"></a>00611
|
|
<a name="l00612"></a>00612 <span class="comment">// Related to <ratio> - minimal to be able to support chrono.</span>
|
|
<a name="l00613"></a>00613 <span class="keyword">typedef</span> <span class="keywordtype">long</span> <span class="keywordtype">long</span> __intmax_t;
|
|
<a name="l00614"></a>00614
|
|
<a name="l00617"></a><a class="code" href="classtthread_1_1ratio.html">00617</a> <span class="keyword">template</span> <__<span class="keywordtype">int</span>max_t N, __<span class="keywordtype">int</span>max_t D = 1> <span class="keyword">class </span><a class="code" href="classtthread_1_1ratio.html" title="Minimal implementation of the ratio class.">ratio</a> {
|
|
<a name="l00618"></a>00618 <span class="keyword">public</span>:
|
|
<a name="l00619"></a>00619 <span class="keyword">static</span> <span class="keywordtype">double</span> _as_double() { <span class="keywordflow">return</span> double(N) / double(D); }
|
|
<a name="l00620"></a>00620 };
|
|
<a name="l00621"></a>00621
|
|
<a name="l00624"></a><a class="code" href="namespacetthread_1_1chrono.html">00624</a> <span class="keyword">namespace </span>chrono {
|
|
<a name="l00627"></a><a class="code" href="classtthread_1_1chrono_1_1duration.html">00627</a> <span class="keyword">template</span> <<span class="keyword">class</span> _Rep, <span class="keyword">class</span> _Period = ratio<1> > <span class="keyword">class </span><a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">duration</a> {
|
|
<a name="l00628"></a>00628 <span class="keyword">private</span>:
|
|
<a name="l00629"></a>00629 _Rep rep_;
|
|
<a name="l00630"></a>00630 <span class="keyword">public</span>:
|
|
<a name="l00631"></a>00631 <span class="keyword">typedef</span> _Rep rep;
|
|
<a name="l00632"></a>00632 <span class="keyword">typedef</span> _Period period;
|
|
<a name="l00633"></a>00633
|
|
<a name="l00635"></a>00635 <span class="keyword">template</span> <<span class="keyword">class</span> _Rep2>
|
|
<a name="l00636"></a><a class="code" href="classtthread_1_1chrono_1_1duration.html#a5d86b0d68c98b74e3a6e541c1759ef3e">00636</a> <span class="keyword">explicit</span> <a class="code" href="classtthread_1_1chrono_1_1duration.html#a5d86b0d68c98b74e3a6e541c1759ef3e" title="Construct a duration object with the given duration.">duration</a>(<span class="keyword">const</span> _Rep2& r) : rep_(r) {};
|
|
<a name="l00637"></a>00637
|
|
<a name="l00639"></a><a class="code" href="classtthread_1_1chrono_1_1duration.html#a3f01111f479d27be202983aacb03c020">00639</a> rep <a class="code" href="classtthread_1_1chrono_1_1duration.html#a3f01111f479d27be202983aacb03c020" title="Return the value of the duration object.">count</a>()<span class="keyword"> const</span>
|
|
<a name="l00640"></a>00640 <span class="keyword"> </span>{
|
|
<a name="l00641"></a>00641 <span class="keywordflow">return</span> rep_;
|
|
<a name="l00642"></a>00642 }
|
|
<a name="l00643"></a>00643 };
|
|
<a name="l00644"></a>00644
|
|
<a name="l00645"></a>00645 <span class="comment">// Standard duration types.</span>
|
|
<a name="l00646"></a><a class="code" href="namespacetthread_1_1chrono.html#a1396eccd0048d613bae0a745b55fa624">00646</a> <span class="keyword">typedef</span> <a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">duration<__intmax_t, ratio<1, 1000000000></a> > <a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">nanoseconds</a>;
|
|
<a name="l00647"></a><a class="code" href="namespacetthread_1_1chrono.html#add152055d7a764f3c1e5af1710f8814f">00647</a> <span class="keyword">typedef</span> <a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">duration<__intmax_t, ratio<1, 1000000></a> > <a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">microseconds</a>;
|
|
<a name="l00648"></a><a class="code" href="namespacetthread_1_1chrono.html#a2cf88065d403d0e61022510769380b75">00648</a> <span class="keyword">typedef</span> <a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">duration<__intmax_t, ratio<1, 1000></a> > <a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">milliseconds</a>;
|
|
<a name="l00649"></a><a class="code" href="namespacetthread_1_1chrono.html#a302ea2e096592e90ec58ccdcc6ec42c3">00649</a> <span class="keyword">typedef</span> <a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">duration<__intmax_t></a> <a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">seconds</a>;
|
|
<a name="l00650"></a><a class="code" href="namespacetthread_1_1chrono.html#a2a9e93851a6aee0eb47cc6379287ee16">00650</a> <span class="keyword">typedef</span> <a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">duration<__intmax_t, ratio<60></a> > <a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">minutes</a>;
|
|
<a name="l00651"></a><a class="code" href="namespacetthread_1_1chrono.html#af212c337748be0da79f5a3a509f36cdf">00651</a> <span class="keyword">typedef</span> <a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">duration<__intmax_t, ratio<3600></a> > <a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">hours</a>;
|
|
<a name="l00652"></a>00652 }
|
|
<a name="l00653"></a>00653
|
|
<a name="l00656"></a><a class="code" href="namespacetthread_1_1this__thread.html">00656</a> <span class="keyword">namespace </span>this_thread {
|
|
<a name="l00658"></a>00658 <a class="code" href="classtthread_1_1thread_1_1id.html" title="Thread ID.">thread::id</a> <a class="code" href="namespacetthread_1_1this__thread.html#ab9370620a3920b9ec550f84fb44fb032" title="Return the thread ID of the calling thread.">get_id</a>();
|
|
<a name="l00659"></a>00659
|
|
<a name="l00663"></a><a class="code" href="namespacetthread_1_1this__thread.html#a867ef7ad1dd6026b7ee13bb013e00edd">00663</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespacetthread_1_1this__thread.html#a867ef7ad1dd6026b7ee13bb013e00edd" title="Yield execution to another thread.">yield</a>()
|
|
<a name="l00664"></a>00664 {
|
|
<a name="l00665"></a>00665 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00666"></a>00666 <span class="preprocessor"></span> Sleep(0);
|
|
<a name="l00667"></a>00667 <span class="preprocessor">#else</span>
|
|
<a name="l00668"></a>00668 <span class="preprocessor"></span> sched_yield();
|
|
<a name="l00669"></a>00669 <span class="preprocessor">#endif</span>
|
|
<a name="l00670"></a>00670 <span class="preprocessor"></span> }
|
|
<a name="l00671"></a>00671
|
|
<a name="l00681"></a><a class="code" href="namespacetthread_1_1this__thread.html#acba48c6dbf12d38ab816c18c1ef96398">00681</a> <span class="keyword">template</span> <<span class="keyword">class</span> _Rep, <span class="keyword">class</span> _Period> <span class="keywordtype">void</span> <a class="code" href="namespacetthread_1_1this__thread.html#acba48c6dbf12d38ab816c18c1ef96398" title="Blocks the calling thread for a period of time.">sleep_for</a>(<span class="keyword">const</span> <a class="code" href="classtthread_1_1chrono_1_1duration.html" title="Duration template class.">chrono::duration<_Rep, _Period></a>& aTime)
|
|
<a name="l00682"></a>00682 {
|
|
<a name="l00683"></a>00683 <span class="preprocessor">#if defined(_TTHREAD_WIN32_)</span>
|
|
<a name="l00684"></a>00684 <span class="preprocessor"></span> Sleep(<span class="keywordtype">int</span>(<span class="keywordtype">double</span>(aTime.<a class="code" href="classtthread_1_1chrono_1_1duration.html#a3f01111f479d27be202983aacb03c020" title="Return the value of the duration object.">count</a>()) * (1000.0 * _Period::_as_double()) + 0.5));
|
|
<a name="l00685"></a>00685 <span class="preprocessor">#else</span>
|
|
<a name="l00686"></a>00686 <span class="preprocessor"></span> usleep(<span class="keywordtype">int</span>(<span class="keywordtype">double</span>(aTime.<a class="code" href="classtthread_1_1chrono_1_1duration.html#a3f01111f479d27be202983aacb03c020" title="Return the value of the duration object.">count</a>()) * (1000000.0 * _Period::_as_double()) + 0.5));
|
|
<a name="l00687"></a>00687 <span class="preprocessor">#endif</span>
|
|
<a name="l00688"></a>00688 <span class="preprocessor"></span> }
|
|
<a name="l00689"></a>00689 }
|
|
<a name="l00690"></a>00690
|
|
<a name="l00691"></a>00691 }
|
|
<a name="l00692"></a>00692
|
|
<a name="l00693"></a>00693 <span class="comment">// Define/macro cleanup</span>
|
|
<a name="l00694"></a>00694 <span class="preprocessor">#undef _TTHREAD_DISABLE_ASSIGNMENT</span>
|
|
<a name="l00695"></a>00695 <span class="preprocessor"></span>
|
|
<a name="l00696"></a>00696 <span class="preprocessor">#endif // _TINYTHREAD_H_</span>
|
|
</pre></div></div>
|
|
<hr class="footer"/><address style="text-align: right;"><small>Generated on Fri Oct 1 21:49:33 2010 for TinyThread++ by
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
|
|
</body>
|
|
</html>
|