4
* Copyright 2002, Emiliano Martin emilianomc@terra.es All rights reserved.
6
* See the COPYING file for the terms of usage and distribution.
9
#ifndef _LOG4SHIB_THREADING_PTHREADS_HH
10
#define _LOG4SHIB_THREADING_PTHREADS_HH
12
#include <log4shib/Portability.hh>
23
* returns the thread ID
25
std::string getThreadId();
31
pthread_mutex_t mutex;
35
::pthread_mutex_init(&mutex, NULL);
39
::pthread_mutex_lock(&mutex);
42
inline void unlock() {
43
::pthread_mutex_unlock(&mutex);
47
::pthread_mutex_destroy(&mutex);
51
Mutex(const Mutex& m);
52
Mutex& operator=(const Mutex &m);
56
* definition of ScopedLock;
63
inline ScopedLock(Mutex& mutex) :
68
inline ~ScopedLock() {
76
template<typename T> class ThreadLocalDataHolder {
83
inline ThreadLocalDataHolder() {
84
::pthread_key_create(&_key, freeHolder);
87
inline static void freeHolder(void *p) {
89
delete reinterpret_cast<T *>(p);
92
inline ~ThreadLocalDataHolder() {
97
::pthread_key_delete(_key);
100
inline T* get() const {
101
return reinterpret_cast<T *>(::pthread_getspecific(_key));
104
inline T* operator->() const { return get(); }
105
inline T& operator*() const { return *get(); }
107
inline T* release() {
109
::pthread_setspecific(_key, NULL);
114
inline void reset(T* p = NULL) {
119
::pthread_setspecific(_key, p);