<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>log4cpp: OmniThreads.hh 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.5.9 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</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>OmniThreads.hh</h1><a href="OmniThreads_8hh.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"> * OmniThreads.hh</span> <a name="l00003"></a>00003 <span class="comment"> *</span> <a name="l00004"></a>00004 <span class="comment"> * Copyright 2002, LifeLine Networks BV (www.lifeline.nl). All rights reserved.</span> <a name="l00005"></a>00005 <span class="comment"> * Copyright 2002, Bastiaan Bakker. All rights reserved.</span> <a name="l00006"></a>00006 <span class="comment"> *</span> <a name="l00007"></a>00007 <span class="comment"> * See the COPYING file for the terms of usage and distribution.</span> <a name="l00008"></a>00008 <span class="comment"> */</span> <a name="l00009"></a>00009 <a name="l00010"></a>00010 <span class="preprocessor">#ifndef _LOG4CPP_THREADING_OMNITHREADS_HH</span> <a name="l00011"></a>00011 <span class="preprocessor"></span><span class="preprocessor">#define _LOG4CPP_THREADING_OMNITHREADS_HH</span> <a name="l00012"></a>00012 <span class="preprocessor"></span> <a name="l00013"></a>00013 <span class="preprocessor">#include <<a class="code" href="Portability_8hh.html">log4cpp/Portability.hh</a>></span> <a name="l00014"></a>00014 <span class="preprocessor">#include <omnithread.h></span> <a name="l00015"></a>00015 <span class="preprocessor">#include <stdio.h></span> <a name="l00016"></a>00016 <span class="preprocessor">#include <string></span> <a name="l00017"></a>00017 <a name="l00018"></a>00018 <span class="keyword">namespace </span>log4cpp { <a name="l00019"></a>00019 <span class="keyword">namespace </span>threading { <a name="l00025"></a>00025 std::string <a class="code" href="namespacelog4cpp_1_1threading.html#f2f7960b92e64a8beb0dcb08ee6bf378" title="Return an identifier for the current thread.">getThreadId</a>(); <a name="l00026"></a>00026 <a name="l00031"></a>00031 <span class="keyword">typedef</span> omni_mutex <a class="code" href="namespacelog4cpp_1_1threading.html#ae98297fe1256bc51b1252c241aef4f1" title="Dummy type &#39;int&#39; for Mutex.">Mutex</a>; <a name="l00032"></a>00032 <a name="l00038"></a>00038 <span class="keyword">typedef</span> omni_mutex_lock <a class="code" href="namespacelog4cpp_1_1threading.html#b5526cf96c18d52f46843e6411d44f7c" title="Dummy type &#39;int&#39; defintion of ScopedLock;.">ScopedLock</a>; <a name="l00039"></a>00039 <a name="l00048"></a>00048 <span class="keyword">template</span><<span class="keyword">typename</span> T> <span class="keyword">class </span>ThreadLocalDataHolder { <a name="l00049"></a>00049 <span class="keyword">public</span>: <a name="l00050"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a720fa8b0bd3ffe97a628c20220f3c6c">00050</a> <span class="keyword">typedef</span> T <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a720fa8b0bd3ffe97a628c20220f3c6c">data_type</a>; <a name="l00051"></a>00051 <a name="l00052"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a9b75c83cd533007ea0c724180a42b6f">00052</a> <span class="keyword">inline</span> <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a9b75c83cd533007ea0c724180a42b6f">ThreadLocalDataHolder</a>() : <a name="l00053"></a>00053 _key(omni_thread::allocate_key()) {}; <a name="l00054"></a>00054 <a name="l00055"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#70be3ec2201a72ba1d1d5eee3764fde9">00055</a> <span class="keyword">inline</span> <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#70be3ec2201a72ba1d1d5eee3764fde9">~ThreadLocalDataHolder</a>() {}; <a name="l00056"></a>00056 <a name="l00062"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#d52fc17c6f4e05576683cd4d05360578">00062</a> <span class="keyword">inline</span> T* <span class="keyword">get</span>() <span class="keyword">const</span> { <a name="l00063"></a>00063 Holder* holder = <span class="keyword">dynamic_cast<</span>Holder*<span class="keyword">></span>( <a name="l00064"></a>00064 ::omni_thread::self()->get_value(_key)); <a name="l00065"></a>00065 <span class="keywordflow">return</span> (holder) ? holder->data : NULL; <a name="l00066"></a>00066 }; <a name="l00067"></a>00067 <a name="l00074"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#0f11f5568a87c5e9e7e4b352e29c5cc5">00074</a> <span class="keyword">inline</span> T* <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#0f11f5568a87c5e9e7e4b352e29c5cc5" title="Obtains the Object held for the current thread.">operator-></a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <span class="keyword">get</span>(); }; <a name="l00075"></a>00075 <a name="l00081"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#3a702989aa1c8e8cc52ad83740a52321">00081</a> <span class="keyword">inline</span> T& <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#3a702989aa1c8e8cc52ad83740a52321" title="Obtains the Object held for the current thread.">operator*</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> *<span class="keyword">get</span>(); }; <a name="l00082"></a>00082 <a name="l00089"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#299e9e1f9e02ef2668e64f81b1d29204">00089</a> <span class="keyword">inline</span> T* <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#299e9e1f9e02ef2668e64f81b1d29204" title="Releases the Object held for the current thread.">release</a>() { <a name="l00090"></a>00090 T* result = NULL; <a name="l00091"></a>00091 Holder* holder = <span class="keyword">dynamic_cast<</span>Holder*<span class="keyword">></span>( <a name="l00092"></a>00092 ::omni_thread::self()->get_value(_key)); <a name="l00093"></a>00093 <a name="l00094"></a>00094 <span class="keywordflow">if</span> (holder) { <a name="l00095"></a>00095 result = holder->data; <a name="l00096"></a>00096 holder->data = NULL; <a name="l00097"></a>00097 } <a name="l00098"></a>00098 <a name="l00099"></a>00099 <span class="keywordflow">return</span> result; <a name="l00100"></a>00100 }; <a name="l00101"></a>00101 <a name="l00108"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#e45b1bbee63188f40ed0a1fd262903dc">00108</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#e45b1bbee63188f40ed0a1fd262903dc" title="Sets a new Object to be held for the current thread.">reset</a>(T* p = NULL) { <a name="l00109"></a>00109 Holder* holder = <span class="keyword">dynamic_cast<</span>Holder*<span class="keyword">></span>( <a name="l00110"></a>00110 ::omni_thread::self()->get_value(_key)); <a name="l00111"></a>00111 <span class="keywordflow">if</span> (holder) { <a name="l00112"></a>00112 <span class="keywordflow">if</span> (holder->data) <a name="l00113"></a>00113 <span class="keyword">delete</span> holder->data; <a name="l00114"></a>00114 <a name="l00115"></a>00115 holder->data = p; <a name="l00116"></a>00116 } <span class="keywordflow">else</span> { <a name="l00117"></a>00117 holder = <span class="keyword">new</span> Holder(p); <a name="l00118"></a>00118 ::omni_thread::self()->set_value(_key, holder); <a name="l00119"></a>00119 } <a name="l00120"></a>00120 }; <a name="l00121"></a>00121 <a name="l00122"></a>00122 <span class="keyword">private</span>: <a name="l00123"></a>00123 <span class="keyword">class </span>Holder : <span class="keyword">public</span> omni_thread::value_t { <a name="l00124"></a>00124 <span class="keyword">public</span>: <a name="l00125"></a>00125 Holder(<a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a720fa8b0bd3ffe97a628c20220f3c6c">data_type</a>* data) : data(data) {}; <a name="l00126"></a>00126 <span class="keyword">virtual</span> ~Holder() { <span class="keywordflow">if</span> (data) <span class="keyword">delete</span> (data); }; <a name="l00127"></a>00127 <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a720fa8b0bd3ffe97a628c20220f3c6c">data_type</a>* data; <a name="l00128"></a>00128 <span class="keyword">private</span>: <a name="l00129"></a>00129 Holder(<span class="keyword">const</span> Holder& other); <a name="l00130"></a>00130 Holder& operator=(<span class="keyword">const</span> Holder& other); <a name="l00131"></a>00131 }; <a name="l00132"></a>00132 <a name="l00133"></a>00133 omni_thread::key_t _key; <a name="l00134"></a>00134 }; <a name="l00135"></a>00135 } <a name="l00136"></a>00136 } <a name="l00137"></a>00137 <span class="preprocessor">#endif</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Sun Jul 26 19:34:50 2009 for log4cpp by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address> </body> </html>