log4cpp
1.1.6
Toggle main menu visibility
Loading...
Searching...
No Matches
PThreads.hh
Go to the documentation of this file.
1
/*
2
* PThreads.hh
3
*
4
* Copyright 2002, Emiliano Martin emilianomc@terra.es All rights reserved.
5
*
6
* See the COPYING file for the terms of usage and distribution.
7
*/
8
9
#ifndef _LOG4CPP_THREADING_PTHREADS_HH
10
#define _LOG4CPP_THREADING_PTHREADS_HH
11
12
#include <assert.h>
13
#include <
log4cpp/Portability.hh
>
14
#include <pthread.h>
15
#include <stdio.h>
16
#include <string>
17
18
namespace
log4cpp
{
19
namespace
threading
{
20
24
std::string
getThreadId
();
25
28
class
Mutex
{
29
private
:
30
pthread_mutex_t mutex;
31
32
public
:
33
inline
Mutex
() {
34
::pthread_mutex_init(&mutex, NULL);
35
}
36
37
inline
void
lock
() {
38
::pthread_mutex_lock(&mutex);
39
}
40
41
inline
void
unlock
() {
42
::pthread_mutex_unlock(&mutex);
43
}
44
45
inline
~Mutex
() {
46
::pthread_mutex_destroy(&mutex);
47
}
48
49
private
:
50
Mutex
(
const
Mutex
& m);
51
Mutex
& operator=(
const
Mutex
& m);
52
};
53
57
class
ScopedLock
{
58
private
:
59
Mutex
& _mutex;
60
61
public
:
62
inline
ScopedLock
(
Mutex
& mutex) : _mutex(mutex) {
63
_mutex.lock();
64
}
65
66
inline
~ScopedLock
() {
67
_mutex.unlock();
68
}
69
};
70
74
template
<
typename
T>
class
ThreadLocalDataHolder {
75
private
:
76
pthread_key_t _key;
77
78
public
:
79
typedef
T
data_type
;
80
81
inline
ThreadLocalDataHolder
() {
82
::pthread_key_create(&_key,
freeHolder
);
83
}
84
85
inline
static
void
freeHolder
(
void
* p) {
86
assert(p != NULL);
87
delete
reinterpret_cast<
T*
>
(p);
88
}
89
90
inline
~ThreadLocalDataHolder
() {
91
T* data =
get
();
92
if
(data != NULL) {
93
delete
data;
94
}
95
::pthread_key_delete(_key);
96
}
97
98
inline
T*
get
()
const
{
99
return
reinterpret_cast<
T*
>
(::pthread_getspecific(_key));
100
}
101
102
inline
T*
operator->
()
const
{
103
return
get
();
104
}
105
inline
T&
operator*
()
const
{
106
return
*
get
();
107
}
108
109
inline
T*
release
() {
110
T* result =
get
();
111
::pthread_setspecific(_key, NULL);
112
113
return
result;
114
}
115
116
inline
void
reset
(T* p = NULL) {
117
T* data =
get
();
118
if
(data != NULL) {
119
delete
data;
120
}
121
::pthread_setspecific(_key, p);
122
}
123
};
124
125
}
// namespace threading
126
}
// namespace log4cpp
127
#endif
Portability.hh
log4cpp::threading::Mutex
Definition
PThreads.hh:28
log4cpp::threading::Mutex::Mutex
Mutex()
Definition
PThreads.hh:33
log4cpp::threading::Mutex::lock
void lock()
Definition
PThreads.hh:37
log4cpp::threading::Mutex::unlock
void unlock()
Definition
PThreads.hh:41
log4cpp::threading::Mutex::~Mutex
~Mutex()
Definition
PThreads.hh:45
log4cpp::threading::ScopedLock::ScopedLock
ScopedLock(Mutex &mutex)
Definition
PThreads.hh:62
log4cpp::threading::ScopedLock::~ScopedLock
~ScopedLock()
Definition
PThreads.hh:66
log4cpp::threading::ThreadLocalDataHolder::~ThreadLocalDataHolder
~ThreadLocalDataHolder()
Definition
PThreads.hh:90
log4cpp::threading::ThreadLocalDataHolder::data_type
T data_type
Definition
DummyThreads.hh:34
log4cpp::threading::ThreadLocalDataHolder::ThreadLocalDataHolder
ThreadLocalDataHolder()
Definition
PThreads.hh:81
log4cpp::threading::ThreadLocalDataHolder::operator->
T * operator->() const
Definition
PThreads.hh:102
log4cpp::threading::ThreadLocalDataHolder::operator*
T & operator*() const
Definition
PThreads.hh:105
log4cpp::threading::ThreadLocalDataHolder::freeHolder
static void freeHolder(void *p)
Definition
PThreads.hh:85
log4cpp::threading::ThreadLocalDataHolder::get
T * get() const
Definition
BoostThreads.hh:34
log4cpp::threading::ThreadLocalDataHolder::reset
void reset(T *p=NULL)
Definition
PThreads.hh:116
log4cpp::threading::ThreadLocalDataHolder::release
T * release()
Definition
PThreads.hh:109
log4cpp::threading
Definition
BoostThreads.hh:21
log4cpp::threading::getThreadId
static std::string getThreadId()
Return an identifier for the current thread.
Definition
BoostThreads.hh:22
log4cpp
The top level namespace for all 'Log for C++' types and classes.
Definition
AbortAppender.hh:16
include
log4cpp
threading
PThreads.hh
Generated by
1.17.0