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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>log4cpp: MSThreads.hh Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="pages.html">Related Pages</a></div>
<div class="nav">
<a class="el" href="dir_000001.html">include</a> / <a class="el" href="dir_000002.html">log4cpp</a> / <a class="el" href="dir_000003.html">threading</a></div>
<h1>MSThreads.hh</h1><a href="MSThreads_8hh.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*</span>
00002 <span class="comment"> * MSThreads.hh</span>
00003 <span class="comment"> *</span>
00004 <span class="comment"> * Copyright 2002, LifeLine Networks BV (www.lifeline.nl). All rights reserved.</span>
00005 <span class="comment"> * Copyright 2002, Bastiaan Bakker. All rights reserved.</span>
00006 <span class="comment"> *</span>
00007 <span class="comment"> * See the COPYING file for the terms of usage and distribution.</span>
00008 <span class="comment"> */</span>
00009
00010 <span class="preprocessor">#ifndef _LOG4CPP_THREADING_MSTHREADS_HH</span>
00011 <span class="preprocessor"></span><span class="preprocessor">#define _LOG4CPP_THREADING_MSTHREADS_HH</span>
00012 <span class="preprocessor"></span>
00013 <span class="preprocessor">#include <string></span>
00014
00015 <span class="comment">// deal with ERROR #define</span>
00016 <span class="comment">// N.B. This #includes windows.h with NOGDI and WIN32_LEAN_AND_MEAN #defined.</span>
00017 <span class="comment">// If this is not what the user wants, #include windows.h before this file.</span>
00018 <span class="preprocessor">#ifndef _WINDOWS_</span>
00019 <span class="preprocessor"></span><span class="preprocessor"># ifndef NOGDI</span>
<a name="l00020"></a><a class="code" href="MSThreads_8hh.html#a0">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#a1">00021</a> <span class="preprocessor"></span><span class="preprocessor"># define LOG4CPP_UNDEFINE_NOGDI</span>
00022 <span class="preprocessor"></span><span class="preprocessor"># endif</span>
00023 <span class="preprocessor"></span>
00024 <span class="preprocessor"># ifndef WIN32_LEAN_AND_MEAN</span>
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#a2">00026</a> <span class="preprocessor"></span><span class="preprocessor"># define LOG4CPP_UNDEFINE_WIN32_LEAN_AND_MEAN</span>
00027 <span class="preprocessor"></span><span class="preprocessor"># endif</span>
00028 <span class="preprocessor"></span>
00029 <span class="preprocessor"># include <windows.h></span>
00030
00031 <span class="preprocessor"># ifdef LOG4CPP_UNDEFINE_NOGDI</span>
00032 <span class="preprocessor"></span><span class="preprocessor"># undef NOGDI</span>
00033 <span class="preprocessor"></span><span class="preprocessor"># endif</span>
00034 <span class="preprocessor"></span>
00035 <span class="preprocessor"># ifdef LOG4CPP_UNDEFINE_WIN32_LEAN_AND_MEAN</span>
00036 <span class="preprocessor"></span><span class="preprocessor"># undef WIN32_LEAN_AND_MEAN</span>
00037 <span class="preprocessor"></span><span class="preprocessor"># endif</span>
00038 <span class="preprocessor"></span>
00039 <span class="preprocessor">#endif // done dealing with ERROR #define</span>
00040 <span class="preprocessor"></span>
00041 <span class="keyword">namespace </span>log4cpp {
00042 <span class="keyword">namespace </span>threading {
00048 std::string <a class="code" href="namespacelog4cpp_1_1threading.html#a2">getThreadId</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#a0">LOG4CPP_EXPORT</a> MSMutex {
00054 <span class="keyword">public</span>:
<a name="l00055"></a><a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html#a0">00055</a> MSMutex() { InitializeCriticalSection(&_criticalSection); }
<a name="l00056"></a><a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html#a1">00056</a> ~MSMutex() { DeleteCriticalSection(&_criticalSection); }
<a name="l00057"></a><a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html#a2">00057</a> <span class="keyword">inline</span> LPCRITICAL_SECTION getCriticalSection() {
00058 <span class="keywordflow">return</span> &_criticalSection;
00059 }
00060
00061 <span class="keyword">private</span>:
00062 MSMutex(<span class="keyword">const</span> MSMutex& other);
00063 CRITICAL_SECTION _criticalSection;
00064 };
00065
00069 <span class="keyword">typedef</span> MSMutex <a class="code" href="namespacelog4cpp_1_1threading.html#a0">Mutex</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">MSScopedLock</a> {
00076 <span class="keyword">public</span>:
<a name="l00077"></a><a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html#a0">00077</a> <a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html#a0">MSScopedLock</a>(MSMutex& mutex) {
00078 _criticalSection = mutex.<a class="code" href="classlog4cpp_1_1threading_1_1MSMutex.html#a2">getCriticalSection</a>();
00079 EnterCriticalSection(_criticalSection);
00080 }
00081
<a name="l00082"></a><a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html#a1">00082</a> <a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html#a1">~MSScopedLock</a>() { LeaveCriticalSection(_criticalSection); }
00083
00084 <span class="keyword">private</span>:
00085 <a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html#a0">MSScopedLock</a>(<span class="keyword">const</span> <a class="code" href="classlog4cpp_1_1threading_1_1MSScopedLock.html">MSScopedLock</a>& other);
00086 LPCRITICAL_SECTION _criticalSection;
00087 };
00088
00093 <span class="keyword">typedef</span> MSScopedLock <a class="code" href="namespacelog4cpp_1_1threading.html#a1">ScopedLock</a>;
00094
<a name="l00101"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html">00101</a> <span class="keyword">template</span><<span class="keyword">typename</span> T> <span class="keyword">class </span><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html">ThreadLocalDataHolder</a> {
00102 <span class="keyword">public</span>:
<a name="l00103"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a12">00103</a> <span class="keyword">inline</span> <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html">ThreadLocalDataHolder</a>() :
00104 _key(TlsAlloc()) {};
00105
<a name="l00106"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a13">00106</a> <span class="keyword">inline</span> ~<a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html">ThreadLocalDataHolder</a>() { TlsFree(_key); };
00107
<a name="l00113"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a14">00113</a> <span class="keyword">inline</span> T* <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a0">get</a>()<span class="keyword"> const </span>{
00114 <span class="keywordflow">return</span> (T*)TlsGetValue(_key);
00115 };
00116
<a name="l00123"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a15">00123</a> <span class="keyword">inline</span> T* <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a1">operator-></a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a0">get</a>(); };
00124
<a name="l00130"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a16">00130</a> <span class="keyword">inline</span> T& operator*()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> *<a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a0">get</a>(); };
00131
<a name="l00138"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a17">00138</a> <span class="keyword">inline</span> T* <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a3">release</a>() {
00139 T* result = (T*)TlsGetValue(_key);
00140 TlsSetValue(_key, NULL);
00141 <span class="keywordflow">return</span> result;
00142 };
00143
<a name="l00150"></a><a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a18">00150</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classlog4cpp_1_1threading_1_1ThreadLocalDataHolder.html#a4">reset</a>(T* p = NULL) {
00151 T* thing = (T*)TlsGetValue(_key);
00152 <span class="keyword">delete</span> thing;
00153 TlsSetValue(_key, p);
00154 };
00155
00156 <span class="keyword">private</span>:
00157 DWORD _key;
00158 };
00159 }
00160 }
00161 <span class="preprocessor">#endif</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Jul 29 14:07:33 2005 for log4cpp by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>
|