File: MSThreads_8hh-source.html

package info (click to toggle)
log4cpp-doc 1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,528 kB
  • sloc: makefile: 10
file content (135 lines) | stat: -rw-r--r-- 14,018 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!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="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.2 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;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>
    <li><a href="pages.html"><span>Related&nbsp;Pages</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="returns the thread ID">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> MSMutex {
<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>             MSMutex() { InitializeCriticalSection(&amp;_criticalSection); }
<a name="l00056"></a><a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html#87d521b673382327334446468c395ee5">00056</a>             ~MSMutex() { 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 getCriticalSection() {
<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             MSMutex(<span class="keyword">const</span> MSMutex&amp; other);
<a name="l00063"></a>00063             CRITICAL_SECTION _criticalSection;
<a name="l00064"></a>00064         };
<a name="l00065"></a>00065 
<a name="l00069"></a><a class="code" href="namespacelog4cpp_1_1threading.html#d023e7822447284d7c21ac9f3697a3b1">00069</a>         <span class="keyword">typedef</span> MSMutex <a class="code" href="classlog4cpp_1_1threading_1_1Mutex.html">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>(MSMutex&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><a class="code" href="namespacelog4cpp_1_1threading.html#e8ca05c4c9a399cdf73d66f5575c0f95">00093</a>         <span class="keyword">typedef</span> <a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html" title="A simple object wrapper around WaitForSingleObject() and ReleaseMutex().">MSScopedLock</a> <a class="code" href="classlog4cpp_1_1threading_1_1ScopedLock.html" title="definition 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><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html" title="This class holds Thread local data of type T, i.e.">ThreadLocalDataHolder</a> {
<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#147cbba1fab8ef3eec6d98ef122749b1">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#f579e5a7fdcba839bf8d95f2ede8a43e">00123</a>             <span class="keyword">inline</span> T* <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#f579e5a7fdcba839bf8d95f2ede8a43e">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#e97fc1f8d6f9c8b11d94c5e213249dbd">00130</a>             <span class="keyword">inline</span> T&amp; <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#e97fc1f8d6f9c8b11d94c5e213249dbd">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">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">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><hr size="1"><address style="text-align: right;"><small>Generated on Mon Sep 3 11:54:29 2007 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.2 </small></address>
</body>
</html>