Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
include
log4cpp
threading
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
LOG4CPP_EXPORT
std::string
getThreadId
();
57
LOG4CPP_EXPORT
char
*
getThreadId
(
char
* buffer);
58
62
class
LOG4CPP_EXPORT
MSMutex
{
63
public
:
64
MSMutex
() { InitializeCriticalSection(&_criticalSection); }
65
~MSMutex
() { DeleteCriticalSection(&_criticalSection); }
66
inline
LPCRITICAL_SECTION
getCriticalSection
() {
67
return
&_criticalSection;
68
}
69
70
private
:
71
MSMutex
(
const
MSMutex
& other);
72
CRITICAL_SECTION
_criticalSection
;
73
};
74
78
typedef
MSMutex
Mutex
;
79
84
class
MSScopedLock
{
85
public
:
86
MSScopedLock
(
MSMutex
& mutex) {
87
_criticalSection = mutex.
getCriticalSection
();
88
EnterCriticalSection(_criticalSection);
89
}
90
91
~MSScopedLock
() { LeaveCriticalSection(_criticalSection); }
92
93
private
:
94
MSScopedLock
(
const
MSScopedLock
& other);
95
LPCRITICAL_SECTION
_criticalSection
;
96
};
97
102
typedef
MSScopedLock
ScopedLock
;
103
110
template
<
typename
T>
class
ThreadLocalDataHolder
{
111
public
:
112
inline
ThreadLocalDataHolder
() :
113
_key(TlsAlloc()) {};
114
115
inline
~ThreadLocalDataHolder
() { TlsFree(_key); };
116
122
inline
T*
get
()
const
{
123
return
(T*)TlsGetValue(_key);
124
};
125
132
inline
T*
operator->
()
const
{
return
get
(); };
133
139
inline
T&
operator*
()
const
{
return
*
get
(); };
140
147
inline
T*
release
() {
148
T* result = (T*)TlsGetValue(_key);
149
TlsSetValue(_key, NULL);
150
return
result;
151
};
152
159
inline
void
reset
(T* p = NULL) {
160
T* thing = (T*)TlsGetValue(_key);
161
delete
thing;
162
TlsSetValue(_key, p);
163
};
164
165
private
:
166
DWORD
_key
;
167
};
168
}
169
}
170
#endif
log4cpp::threading::ThreadLocalDataHolder::operator*
T & operator*() const
Definition:
MSThreads.hh:139
log4cpp::threading::ThreadLocalDataHolder
Definition:
BoostThreads.hh:42
log4cpp::threading::ThreadLocalDataHolder::~ThreadLocalDataHolder
~ThreadLocalDataHolder()
Definition:
MSThreads.hh:115
log4cpp::threading::MSScopedLock::MSScopedLock
MSScopedLock(MSMutex &mutex)
Definition:
MSThreads.hh:86
log4cpp::threading::getThreadId
static std::string getThreadId()
Definition:
BoostThreads.hh:22
log4cpp::threading::MSScopedLock::_criticalSection
LPCRITICAL_SECTION _criticalSection
Definition:
MSThreads.hh:95
log4cpp::threading::MSMutex::_criticalSection
CRITICAL_SECTION _criticalSection
Definition:
MSThreads.hh:72
log4cpp::threading::ThreadLocalDataHolder::operator->
T * operator->() const
Definition:
MSThreads.hh:132
log4cpp::threading::MSScopedLock
Definition:
MSThreads.hh:84
log4cpp::threading::ThreadLocalDataHolder::ThreadLocalDataHolder
ThreadLocalDataHolder()
Definition:
MSThreads.hh:112
log4cpp::threading::ThreadLocalDataHolder::release
T * release()
Definition:
MSThreads.hh:147
LOG4CPP_EXPORT
#define LOG4CPP_EXPORT
Definition:
Export.hh:26
log4cpp
Definition:
AbortAppender.hh:16
log4cpp::threading::Mutex
boost::mutex Mutex
Definition:
BoostThreads.hh:37
log4cpp::threading::ThreadLocalDataHolder::reset
void reset(T *p=NULL)
Definition:
MSThreads.hh:159
log4cpp::threading::MSMutex::MSMutex
MSMutex()
Definition:
MSThreads.hh:64
log4cpp::threading::MSMutex
Definition:
MSThreads.hh:62
log4cpp::threading::ScopedLock
boost::mutex::scoped_lock ScopedLock
Definition:
BoostThreads.hh:40
log4cpp::threading::ThreadLocalDataHolder::_key
DWORD _key
Definition:
MSThreads.hh:163
log4cpp::threading::MSScopedLock::~MSScopedLock
~MSScopedLock()
Definition:
MSThreads.hh:91
log4cpp::threading::MSMutex::getCriticalSection
LPCRITICAL_SECTION getCriticalSection()
Definition:
MSThreads.hh:66
log4cpp::threading::MSMutex::~MSMutex
~MSMutex()
Definition:
MSThreads.hh:65
log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Jun 23 2019 19:10:00