Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 5fc82cd2dfd40b1b8acca39dd2860281 > files > 88

log4cpp-1.0-4.fc12.i686.rpm

<!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: MSThreads.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&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;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&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>MSThreads.hh</h1><a href="MSThreads_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"> * MSThreads.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_MSTHREADS_HH</span>
<a name="l00011"></a>00011 <span class="preprocessor"></span><span class="preprocessor">#define _LOG4CPP_THREADING_MSTHREADS_HH</span>
<a name="l00012"></a>00012 <span class="preprocessor"></span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 <span class="comment">// deal with ERROR #define</span>
<a name="l00016"></a>00016 <span class="comment">// N.B. This #includes windows.h with NOGDI and WIN32_LEAN_AND_MEAN #defined.</span>
<a name="l00017"></a>00017 <span class="comment">//      If this is not what the user wants, #include windows.h before this file.</span>
<a name="l00018"></a>00018 <span class="preprocessor">#ifndef _WINDOWS_</span>
<a name="l00019"></a>00019 <span class="preprocessor"></span><span class="preprocessor">#  ifndef NOGDI</span>
<a name="l00020"></a><a class="code" href="MSThreads_8hh.html#2bedaca1c6ca66de2397772910fbe140">00020</a> <span class="preprocessor"></span><span class="preprocessor">#    define NOGDI  // this will circumvent the ERROR #define in windows.h</span>
<a name="l00021"></a><a class="code" href="MSThreads_8hh.html#61fa37f681d42a0cdcc1ec269b2112e7">00021</a> <span class="preprocessor"></span><span class="preprocessor">#    define LOG4CPP_UNDEFINE_NOGDI</span>
<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#  endif</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span>
<a name="l00024"></a>00024 <span class="preprocessor">#  ifndef WIN32_LEAN_AND_MEAN</span>
<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#    define WIN32_LEAN_AND_MEAN</span>
<a name="l00026"></a><a class="code" href="MSThreads_8hh.html#45d33c1cc71858b437dd4f3a0d594d89">00026</a> <span class="preprocessor"></span><span class="preprocessor">#    define LOG4CPP_UNDEFINE_WIN32_LEAN_AND_MEAN</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#  endif</span>
<a name="l00028"></a>00028 <span class="preprocessor"></span>
<a name="l00029"></a>00029 <span class="preprocessor">#  include &lt;windows.h&gt;</span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="preprocessor">#  ifdef LOG4CPP_UNDEFINE_NOGDI</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#    undef NOGDI</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#  endif</span>
<a name="l00034"></a>00034 <span class="preprocessor"></span>
<a name="l00035"></a>00035 <span class="preprocessor">#  ifdef LOG4CPP_UNDEFINE_WIN32_LEAN_AND_MEAN</span>
<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#    undef WIN32_LEAN_AND_MEAN</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#  endif</span>
<a name="l00038"></a>00038 <span class="preprocessor"></span>
<a name="l00039"></a>00039 <span class="preprocessor">#endif // done dealing with ERROR #define</span>
<a name="l00040"></a>00040 <span class="preprocessor"></span>
<a name="l00041"></a>00041 <span class="keyword">namespace </span>log4cpp {
<a name="l00042"></a>00042     <span class="keyword">namespace </span>threading {
<a name="l00048"></a>00048         std::string <a class="code" href="namespacelog4cpp_1_1threading.html#f2f7960b92e64a8beb0dcb08ee6bf378" title="Return an identifier for the current thread.">getThreadId</a>();
<a name="l00049"></a>00049         
<a name="l00053"></a><a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html">00053</a>         <span class="keyword">class </span><a class="code" href="Export_8hh.html#30f9ff9641fa394781f52398a8312437">LOG4CPP_EXPORT</a> <a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html" title="A simple object wrapper around CreateMutex() and DeleteMutex().">MSMutex</a> {
<a name="l00054"></a>00054             <span class="keyword">public</span>:
<a name="l00055"></a><a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html#5a39be624d2fe0ca6c4497ad13fbfafc">00055</a>             <a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html#5a39be624d2fe0ca6c4497ad13fbfafc">MSMutex</a>() { InitializeCriticalSection(&amp;_criticalSection); }
<a name="l00056"></a><a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html#87d521b673382327334446468c395ee5">00056</a>             <a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html#87d521b673382327334446468c395ee5">~MSMutex</a>() { DeleteCriticalSection(&amp;_criticalSection); }
<a name="l00057"></a><a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html#0055996e413beeb6befa7b20d276f374">00057</a>             <span class="keyword">inline</span> LPCRITICAL_SECTION <a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html#0055996e413beeb6befa7b20d276f374">getCriticalSection</a>() {
<a name="l00058"></a>00058                 <span class="keywordflow">return</span> &amp;_criticalSection;
<a name="l00059"></a>00059             }
<a name="l00060"></a>00060 
<a name="l00061"></a>00061             <span class="keyword">private</span>:
<a name="l00062"></a>00062             <a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html" title="A simple object wrapper around CreateMutex() and DeleteMutex().">MSMutex</a>(<span class="keyword">const</span> <a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html" title="A simple object wrapper around CreateMutex() and DeleteMutex().">MSMutex</a>&amp; other);
<a name="l00063"></a>00063             CRITICAL_SECTION _criticalSection;
<a name="l00064"></a>00064         };
<a name="l00065"></a>00065 
<a name="l00069"></a>00069         <span class="keyword">typedef</span> MSMutex <a class="code" href="namespacelog4cpp_1_1threading.html#ae98297fe1256bc51b1252c241aef4f1" title="Dummy type &amp;#39;int&amp;#39; for Mutex.">Mutex</a>;
<a name="l00070"></a>00070 
<a name="l00075"></a><a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html">00075</a>         <span class="keyword">class </span><a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html" title="A simple object wrapper around WaitForSingleObject() and ReleaseMutex().">MSScopedLock</a> {
<a name="l00076"></a>00076             <span class="keyword">public</span>:
<a name="l00077"></a><a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html#49e930a94ae3da89cf0348bff5e37c2b">00077</a>             <a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html#49e930a94ae3da89cf0348bff5e37c2b">MSScopedLock</a>(<a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html" title="A simple object wrapper around CreateMutex() and DeleteMutex().">MSMutex</a>&amp; mutex) {
<a name="l00078"></a>00078                 _criticalSection = mutex.<a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html#0055996e413beeb6befa7b20d276f374">getCriticalSection</a>();
<a name="l00079"></a>00079                 EnterCriticalSection(_criticalSection);
<a name="l00080"></a>00080             }
<a name="l00081"></a>00081 
<a name="l00082"></a><a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html#6ccf7245ac4e909c2c33482942426f67">00082</a>             <a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html#6ccf7245ac4e909c2c33482942426f67">~MSScopedLock</a>() { LeaveCriticalSection(_criticalSection); }
<a name="l00083"></a>00083 
<a name="l00084"></a>00084             <span class="keyword">private</span>:
<a name="l00085"></a>00085             <a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html#49e930a94ae3da89cf0348bff5e37c2b">MSScopedLock</a>(<span class="keyword">const</span> <a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html" title="A simple object wrapper around WaitForSingleObject() and ReleaseMutex().">MSScopedLock</a>&amp; other);
<a name="l00086"></a>00086             LPCRITICAL_SECTION _criticalSection;
<a name="l00087"></a>00087         };
<a name="l00088"></a>00088 
<a name="l00093"></a>00093         <span class="keyword">typedef</span> MSScopedLock <a class="code" href="namespacelog4cpp_1_1threading.html#b5526cf96c18d52f46843e6411d44f7c" title="Dummy type &amp;#39;int&amp;#39; defintion of ScopedLock;.">ScopedLock</a>;
<a name="l00094"></a>00094 
<a name="l00101"></a>00101         <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt; <span class="keyword">class </span>ThreadLocalDataHolder {
<a name="l00102"></a>00102             <span class="keyword">public</span>:
<a name="l00103"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a9b75c83cd533007ea0c724180a42b6f">00103</a>             <span class="keyword">inline</span> <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a9b75c83cd533007ea0c724180a42b6f">ThreadLocalDataHolder</a>() :
<a name="l00104"></a>00104                 _key(TlsAlloc()) {};
<a name="l00105"></a>00105 
<a name="l00106"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#70be3ec2201a72ba1d1d5eee3764fde9">00106</a>             <span class="keyword">inline</span> <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#70be3ec2201a72ba1d1d5eee3764fde9">~ThreadLocalDataHolder</a>() { TlsFree(_key); };
<a name="l00107"></a>00107             
<a name="l00113"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#d52fc17c6f4e05576683cd4d05360578">00113</a>             <span class="keyword">inline</span> T* <span class="keyword">get</span>() <span class="keyword">const</span> {
<a name="l00114"></a>00114                 <span class="keywordflow">return</span> (T*)TlsGetValue(_key);
<a name="l00115"></a>00115             };
<a name="l00116"></a>00116 
<a name="l00123"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#0f11f5568a87c5e9e7e4b352e29c5cc5">00123</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-&gt;</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <span class="keyword">get</span>(); };
<a name="l00124"></a>00124 
<a name="l00130"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#3a702989aa1c8e8cc52ad83740a52321">00130</a>             <span class="keyword">inline</span> T&amp; <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="l00131"></a>00131 
<a name="l00138"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#299e9e1f9e02ef2668e64f81b1d29204">00138</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="l00139"></a>00139                 T* result = (T*)TlsGetValue(_key);
<a name="l00140"></a>00140                 TlsSetValue(_key, NULL);
<a name="l00141"></a>00141                 <span class="keywordflow">return</span> result;
<a name="l00142"></a>00142             };
<a name="l00143"></a>00143 
<a name="l00150"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#e45b1bbee63188f40ed0a1fd262903dc">00150</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="l00151"></a>00151                 T* thing = (T*)TlsGetValue(_key);
<a name="l00152"></a>00152                 <span class="keyword">delete</span> thing;
<a name="l00153"></a>00153                 TlsSetValue(_key, p);
<a name="l00154"></a>00154             };
<a name="l00155"></a>00155 
<a name="l00156"></a>00156             <span class="keyword">private</span>:            
<a name="l00157"></a>00157             DWORD _key;            
<a name="l00158"></a>00158         };
<a name="l00159"></a>00159     }
<a name="l00160"></a>00160 }
<a name="l00161"></a>00161 <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&nbsp;
<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>