log4cpp
1.1.6
Toggle main menu visibility
Loading...
Searching...
No Matches
MSThreads.hh
Go to the documentation of this file.
1
/*
2
* MSThreads.hh
3
*
4
* Copyright 2002, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
5
* Copyright 2002, Bastiaan Bakker. All rights reserved.
6
*
7
* See the COPYING file for the terms of usage and distribution.
8
*/
9
10
#ifndef _LOG4CPP_THREADING_MSTHREADS_HH
11
#define _LOG4CPP_THREADING_MSTHREADS_HH
12
13
#include <string>
14
15
// deal with ERROR #define
16
// N.B. This #includes windows.h with NOGDI and WIN32_LEAN_AND_MEAN #defined.
17
// If this is not what the user wants, #include windows.h before this file.
18
#ifndef _WINDOWS_
19
#ifndef NOGDI
20
#define NOGDI
// this will circumvent the ERROR #define in windows.h
21
#define LOG4CPP_UNDEFINE_NOGDI
22
#endif
23
24
#ifndef WIN32_LEAN_AND_MEAN
25
#define WIN32_LEAN_AND_MEAN
26
#define LOG4CPP_UNDEFINE_WIN32_LEAN_AND_MEAN
27
#endif
28
29
#include <windows.h>
30
31
#ifdef LOG4CPP_UNDEFINE_NOGDI
32
#undef NOGDI
33
#endif
34
35
#ifdef LOG4CPP_UNDEFINE_WIN32_LEAN_AND_MEAN
36
#undef WIN32_LEAN_AND_MEAN
37
#endif
38
39
#endif
// done dealing with ERROR #define
40
41
namespace
log4cpp
{
42
namespace
threading {
48
std::string getThreadId();
49
53
class
LOG4CPP_EXPORT
MSMutex
{
54
public
:
55
MSMutex
() {
56
InitializeCriticalSection(&_criticalSection);
57
}
58
~MSMutex
() {
59
DeleteCriticalSection(&_criticalSection);
60
}
61
inline
LPCRITICAL_SECTION
getCriticalSection
() {
62
return
&_criticalSection;
63
}
64
65
private
:
66
MSMutex
(
const
MSMutex
& other);
67
CRITICAL_SECTION _criticalSection;
68
};
69
73
typedef
MSMutex
Mutex
;
74
79
class
MSScopedLock
{
80
public
:
81
MSScopedLock
(
MSMutex
& mutex) {
82
_criticalSection = mutex.
getCriticalSection
();
83
EnterCriticalSection(_criticalSection);
84
}
85
86
~MSScopedLock
() {
87
LeaveCriticalSection(_criticalSection);
88
}
89
90
private
:
91
MSScopedLock
(
const
MSScopedLock
& other);
92
LPCRITICAL_SECTION _criticalSection;
93
};
94
99
typedef
MSScopedLock
ScopedLock
;
100
107
template
<
typename
T>
class
ThreadLocalDataHolder {
108
public
:
109
inline
ThreadLocalDataHolder
() : _key(TlsAlloc()) {};
110
111
inline
~ThreadLocalDataHolder
() {
112
TlsFree(_key);
113
};
114
120
inline
T*
get
()
const
{
121
return
(T*)TlsGetValue(_key);
122
};
123
130
inline
T*
operator->
()
const
{
131
return
get
();
132
};
133
139
inline
T&
operator*
()
const
{
140
return
*
get
();
141
};
142
149
inline
T*
release
() {
150
T* result = (T*)TlsGetValue(_key);
151
TlsSetValue(_key, NULL);
152
return
result;
153
};
154
161
inline
void
reset
(T* p = NULL) {
162
T* thing = (T*)TlsGetValue(_key);
163
delete
thing;
164
TlsSetValue(_key, p);
165
};
166
167
private
:
168
DWORD _key;
169
};
170
}
// namespace threading
171
}
// namespace log4cpp
172
#endif
LOG4CPP_EXPORT
#define LOG4CPP_EXPORT
Definition
Export.hh:26
log4cpp::threading::MSMutex
A simple object wrapper around CreateMutex() and DeleteMutex().
Definition
MSThreads.hh:53
log4cpp::threading::MSMutex::getCriticalSection
LPCRITICAL_SECTION getCriticalSection()
Definition
MSThreads.hh:61
log4cpp::threading::MSMutex::MSMutex
MSMutex()
Definition
MSThreads.hh:55
log4cpp::threading::MSMutex::~MSMutex
~MSMutex()
Definition
MSThreads.hh:58
log4cpp::threading::MSScopedLock
A simple object wrapper around WaitForSingleObject() and ReleaseMutex().
Definition
MSThreads.hh:79
log4cpp::threading::MSScopedLock::MSScopedLock
MSScopedLock(MSMutex &mutex)
Definition
MSThreads.hh:81
log4cpp::threading::MSScopedLock::~MSScopedLock
~MSScopedLock()
Definition
MSThreads.hh:86
log4cpp::threading::ThreadLocalDataHolder::~ThreadLocalDataHolder
~ThreadLocalDataHolder()
Definition
MSThreads.hh:111
log4cpp::threading::ThreadLocalDataHolder::ThreadLocalDataHolder
ThreadLocalDataHolder()
Definition
MSThreads.hh:109
log4cpp::threading::ThreadLocalDataHolder::operator->
T * operator->() const
Obtains the Object held for the current thread.
Definition
MSThreads.hh:130
log4cpp::threading::ThreadLocalDataHolder::operator*
T & operator*() const
Obtains the Object held for the current thread.
Definition
MSThreads.hh:139
log4cpp::threading::ThreadLocalDataHolder::get
T * get() const
Obtains the Object held for the current thread.
Definition
MSThreads.hh:120
log4cpp::threading::ThreadLocalDataHolder::reset
void reset(T *p=NULL)
Sets a new Object to be held for the current thread.
Definition
MSThreads.hh:161
log4cpp::threading::ThreadLocalDataHolder::release
T * release()
Releases the Object held for the current thread.
Definition
MSThreads.hh:149
log4cpp::threading::Mutex
boost::mutex Mutex
Dummy type 'int' for Mutex.
Definition
BoostThreads.hh:29
log4cpp::threading::ScopedLock
boost::mutex::scoped_lock ScopedLock
Dummy type 'int' defintion of ScopedLock;.
Definition
BoostThreads.hh:30
log4cpp
The top level namespace for all 'Log for C++' types and classes.
Definition
AbortAppender.hh:16
include
log4cpp
threading
MSThreads.hh
Generated by
1.18.0