forked from orocos-toolchain/log4cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoostThreads.hh
More file actions
65 lines (55 loc) · 1.77 KB
/
BoostThreads.hh
File metadata and controls
65 lines (55 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* BoostThreads.hh
*
* Copyright 2002, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
* Copyright 2002, Bastiaan Bakker. All rights reserved.
*
* See the COPYING file for the terms of usage and distribution.
*/
#ifndef _LOG4CPP_THREADING_BOOSTTHREADS_HH
#define _LOG4CPP_THREADING_BOOSTTHREADS_HH
#include <log4cpp/Portability.hh>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/tss.hpp>
#include <cstdio>
#include <string>
namespace log4cpp {
namespace threading {
static std::string getThreadId() {
char buffer[14];
// Boost.Threads stores the thread ID but doesn't expose it
sprintf(buffer, "not available");
return std::string(buffer);
};
/**
* returns the thread ID
* @param buffer Character buffer of at least 14 in size
* @return buffer
*/
static char* getThreadId(char* buffer) {
// Boost.Threads stores the thread ID but doesn't expose it
sprintf(buffer, "not available");
return buffer;
};
typedef boost::mutex Mutex;
typedef boost::mutex::scoped_lock ScopedLock;
template<typename T> class ThreadLocalDataHolder {
public:
inline T* get() const {
return _localData.get();
};
inline T* operator->() const { return _localData.get(); };
inline T& operator*() const { return *_localData.get(); };
inline T* release() {
return _localData.release();
};
inline void reset(T* p = NULL) {
_localData.reset(p);
};
private:
boost::thread_specific_ptr<T> _localData;
};
}
}
#endif