log4cpp
1.1.6
Toggle main menu visibility
Loading...
Searching...
No Matches
OmniThreads.hh
Go to the documentation of this file.
1
/*
2
* OmniThreads.hh
3
*
4
* Copyright 2002, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
5
* Copyright 2002, Bastiaan Bakker. All rights reserved.
6
*
7
* See the COPYING file for the terms of usage and distribution.
8
*/
9
10
#ifndef _LOG4CPP_THREADING_OMNITHREADS_HH
11
#define _LOG4CPP_THREADING_OMNITHREADS_HH
12
13
#include <
log4cpp/Portability.hh
>
14
#include <omnithread.h>
15
#include <stdio.h>
16
#include <string>
17
18
namespace
log4cpp
{
19
namespace
threading
{
25
std::string
getThreadId
();
26
31
typedef
omni_mutex
Mutex
;
32
38
typedef
omni_mutex_lock
ScopedLock
;
39
48
template
<
typename
T>
class
ThreadLocalDataHolder
{
49
public
:
50
typedef
T
data_type
;
51
52
inline
ThreadLocalDataHolder
() : _key(omni_thread::allocate_key()) {};
53
54
inline
~ThreadLocalDataHolder
() {};
55
61
inline
T*
get
()
const
{
62
Holder* holder =
dynamic_cast<
Holder*
>
(::omni_thread::self()->get_value(_key));
63
return
(holder) ? holder->data : NULL;
64
};
65
72
inline
T*
operator->
()
const
{
73
return
get
();
74
};
75
81
inline
T&
operator*
()
const
{
82
return
*
get
();
83
};
84
91
inline
T*
release
() {
92
T* result = NULL;
93
Holder* holder =
dynamic_cast<
Holder*
>
(::omni_thread::self()->get_value(_key));
94
95
if
(holder) {
96
result = holder->data;
97
holder->data = NULL;
98
}
99
100
return
result;
101
};
102
109
inline
void
reset
(T* p = NULL) {
110
Holder* holder =
dynamic_cast<
Holder*
>
(::omni_thread::self()->get_value(_key));
111
if
(holder) {
112
if
(holder->data)
113
delete
holder->data;
114
115
holder->data = p;
116
}
else
{
117
holder =
new
Holder(p);
118
::omni_thread::self()->set_value(_key, holder);
119
}
120
};
121
122
private
:
123
class
Holder :
public
omni_thread::value_t {
124
public
:
125
Holder(
data_type
* data) : data(data) {};
126
virtual
~Holder() {
127
if
(data)
128
delete
(data);
129
};
130
data_type
* data;
131
132
private
:
133
Holder(
const
Holder& other);
134
Holder& operator=(
const
Holder& other);
135
};
136
137
omni_thread::key_t _key;
138
};
139
}
// namespace threading
140
}
// namespace log4cpp
141
#endif
Portability.hh
log4cpp::threading::Mutex
Definition
PThreads.hh:28
log4cpp::threading::ScopedLock
definition of ScopedLock;
Definition
PThreads.hh:57
log4cpp::threading::ThreadLocalDataHolder
This class holds Thread local data of type T, i.e.
Definition
BoostThreads.hh:32
log4cpp::threading::ThreadLocalDataHolder::~ThreadLocalDataHolder
~ThreadLocalDataHolder()
Definition
OmniThreads.hh:54
log4cpp::threading::ThreadLocalDataHolder::data_type
T data_type
Definition
DummyThreads.hh:34
log4cpp::threading::ThreadLocalDataHolder::ThreadLocalDataHolder
ThreadLocalDataHolder()
Definition
OmniThreads.hh:52
log4cpp::threading::ThreadLocalDataHolder::operator->
T * operator->() const
Obtains the Object held for the current thread.
Definition
OmniThreads.hh:72
log4cpp::threading::ThreadLocalDataHolder::operator*
T & operator*() const
Obtains the Object held for the current thread.
Definition
OmniThreads.hh:81
log4cpp::threading::ThreadLocalDataHolder::get
T * get() const
Obtains the Object held for the current thread.
Definition
OmniThreads.hh:61
log4cpp::threading::ThreadLocalDataHolder::reset
void reset(T *p=NULL)
Sets a new Object to be held for the current thread.
Definition
OmniThreads.hh:109
log4cpp::threading::ThreadLocalDataHolder::release
T * release()
Releases the Object held for the current thread.
Definition
OmniThreads.hh:91
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
OmniThreads.hh
Generated by
1.17.0