Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
include
log4cpp
threading
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 <
log4cpp/Portability.hh
>
13
#include <stdio.h>
14
#include <pthread.h>
15
#include <string>
16
#include <assert.h>
17
18
19
namespace
log4cpp
{
20
namespace
threading {
21
25
std::string
getThreadId
();
26
32
char
*
getThreadId
(
char
* buffer);
33
36
class
Mutex
{
37
private
:
38
pthread_mutex_t
mutex
;
39
40
public
:
41
inline
Mutex
() {
42
::pthread_mutex_init(&mutex, NULL);
43
}
44
45
inline
void
lock
() {
46
::pthread_mutex_lock(&mutex);
47
}
48
49
inline
void
unlock
() {
50
::pthread_mutex_unlock(&mutex);
51
}
52
53
inline
~Mutex
() {
54
::pthread_mutex_destroy(&mutex);
55
}
56
57
private
:
58
Mutex
(
const
Mutex
& m);
59
Mutex
&
operator=
(
const
Mutex
&m);
60
};
61
65
class
ScopedLock
{
66
private
:
67
Mutex
&
_mutex
;
68
69
public
:
70
inline
ScopedLock
(
Mutex
&
mutex
) :
71
_mutex(mutex) {
72
_mutex.
lock
();
73
}
74
75
inline
~ScopedLock
() {
76
_mutex.
unlock
();
77
}
78
};
79
83
template
<
typename
T>
class
ThreadLocalDataHolder
{
84
private
:
85
pthread_key_t
_key
;
86
87
public
:
88
typedef
T
data_type
;
89
90
inline
ThreadLocalDataHolder
() {
91
::pthread_key_create(&_key, freeHolder);
92
}
93
94
inline
static
void
freeHolder
(
void
*p) {
95
assert(p != NULL);
96
delete
reinterpret_cast<
T *
>
(p);
97
}
98
99
inline
~ThreadLocalDataHolder
() {
100
T *data =
get
();
101
if
(data != NULL) {
102
delete
data;
103
}
104
::pthread_key_delete(_key);
105
}
106
107
inline
T*
get
()
const
{
108
return
reinterpret_cast<
T *
>
(::pthread_getspecific(_key));
109
}
110
111
inline
T*
operator->
()
const
{
return
get
(); }
112
inline
T&
operator*
()
const
{
return
*
get
(); }
113
114
inline
T*
release
() {
115
T* result =
get
();
116
::pthread_setspecific(_key, NULL);
117
118
return
result;
119
}
120
121
inline
void
reset
(T* p = NULL) {
122
T *data =
get
();
123
if
(data != NULL) {
124
delete
data;
125
}
126
::pthread_setspecific(_key, p);
127
}
128
};
129
130
}
131
}
132
#endif
log4cpp::threading::ThreadLocalDataHolder::operator*
T & operator*() const
Definition:
PThreads.hh:112
log4cpp::threading::ThreadLocalDataHolder
Definition:
BoostThreads.hh:42
log4cpp::threading::ThreadLocalDataHolder::~ThreadLocalDataHolder
~ThreadLocalDataHolder()
Definition:
PThreads.hh:99
log4cpp::threading::Mutex::operator=
Mutex & operator=(const Mutex &m)
log4cpp::threading::ThreadLocalDataHolder::data_type
T data_type
Definition:
PThreads.hh:88
log4cpp::threading::ThreadLocalDataHolder::freeHolder
static void freeHolder(void *p)
Definition:
PThreads.hh:94
log4cpp::threading::Mutex::~Mutex
~Mutex()
Definition:
PThreads.hh:53
log4cpp::threading::ScopedLock
Definition:
PThreads.hh:65
log4cpp::threading::Mutex::lock
void lock()
Definition:
PThreads.hh:45
log4cpp::threading::Mutex::mutex
pthread_mutex_t mutex
Definition:
PThreads.hh:38
log4cpp::threading::getThreadId
static std::string getThreadId()
Definition:
BoostThreads.hh:22
Portability.hh
log4cpp::threading::ThreadLocalDataHolder::operator->
T * operator->() const
Definition:
PThreads.hh:111
log4cpp::threading::Mutex::unlock
void unlock()
Definition:
PThreads.hh:49
log4cpp::threading::ThreadLocalDataHolder::ThreadLocalDataHolder
ThreadLocalDataHolder()
Definition:
PThreads.hh:90
log4cpp::threading::ThreadLocalDataHolder::release
T * release()
Definition:
PThreads.hh:114
log4cpp::threading::ThreadLocalDataHolder::_key
pthread_key_t _key
Definition:
PThreads.hh:85
log4cpp
Definition:
AbortAppender.hh:16
log4cpp::threading::ScopedLock::_mutex
Mutex & _mutex
Definition:
PThreads.hh:67
log4cpp::threading::Mutex::Mutex
Mutex()
Definition:
PThreads.hh:41
log4cpp::threading::ThreadLocalDataHolder::reset
void reset(T *p=NULL)
Definition:
PThreads.hh:121
log4cpp::threading::Mutex
Definition:
PThreads.hh:36
log4cpp::threading::ScopedLock::ScopedLock
ScopedLock(Mutex &mutex)
Definition:
PThreads.hh:70
log4cpp::threading::ScopedLock::~ScopedLock
~ScopedLock()
Definition:
PThreads.hh:75
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