10 #ifndef _LOG4CPP_THREADING_OMNITHREADS_HH
11 #define _LOG4CPP_THREADING_OMNITHREADS_HH
14 #include <omnithread.h>
31 typedef omni_mutex
Mutex;
48 template<
typename T>
class ThreadLocalDataHolder {
53 _key(omni_thread::allocate_key()) {};
62 inline T*
get()
const {
63 Holder* holder =
dynamic_cast<Holder*
>(
64 ::omni_thread::self()->get_value(_key));
65 return (holder) ? holder->data : NULL;
91 Holder* holder =
dynamic_cast<Holder*
>(
92 ::omni_thread::self()->get_value(_key));
95 result = holder->data;
109 Holder* holder =
dynamic_cast<Holder*
>(
110 ::omni_thread::self()->get_value(_key));
117 holder =
new Holder(p);
118 ::omni_thread::self()->set_value(_key, holder);
123 class Holder :
public omni_thread::value_t {
126 virtual ~Holder() {
if (data)
delete (data); };
129 Holder(
const Holder& other);
130 Holder& operator=(
const Holder& other);
133 omni_thread::key_t _key;
T * get() const
Obtains the Object held for the current thread.
Definition: OmniThreads.hh:62
T * release()
Releases the Object held for the current thread.
Definition: OmniThreads.hh:89
~ThreadLocalDataHolder()
Definition: OmniThreads.hh:55
T & operator*() const
Obtains the Object held for the current thread.
Definition: OmniThreads.hh:81
T data_type
Definition: OmniThreads.hh:50
ThreadLocalDataHolder()
Definition: OmniThreads.hh:52
void reset(T *p=NULL)
Sets a new Object to be held for the current thread.
Definition: OmniThreads.hh:108
T * operator->() const
Obtains the Object held for the current thread.
Definition: OmniThreads.hh:74
boost::mutex Mutex
Dummy type 'int' for Mutex.
Definition: BoostThreads.hh:27
boost::mutex::scoped_lock ScopedLock
Dummy type 'int' defintion of ScopedLock;.
Definition: BoostThreads.hh:30
static std::string getThreadId()
Return an identifier for the current thread.
Definition: BoostThreads.hh:22
The top level namespace for all 'Log for C++' types and classes.
Definition: AbortAppender.hh:16