Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
include
log4cpp
threading
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
35
char
*
getThreadId
(
char
* buffer);
36
41
typedef
omni_mutex
Mutex
;
42
48
typedef
omni_mutex_lock
ScopedLock
;
49
58
template
<
typename
T>
class
ThreadLocalDataHolder {
59
public
:
60
typedef
T
data_type
;
61
62
inline
ThreadLocalDataHolder
() :
63
_key
(omni_thread::allocate_key()) {};
64
65
inline
~ThreadLocalDataHolder
() {};
66
72
inline
T*
get
()
const
{
73
Holder
* holder =
dynamic_cast<
Holder
*
>
(
74
::omni_thread::self()->get_value(
_key
));
75
return
(holder) ? holder->
data
: NULL;
76
};
77
84
inline
T*
operator->
()
const
{
return
get
(); };
85
91
inline
T&
operator*
()
const
{
return
*
get
(); };
92
99
inline
T*
release
() {
100
T* result = NULL;
101
Holder
* holder =
dynamic_cast<
Holder
*
>
(
102
::omni_thread::self()->get_value(
_key
));
103
104
if
(holder) {
105
result = holder->
data
;
106
holder->
data
= NULL;
107
}
108
109
return
result;
110
};
111
118
inline
void
reset
(T* p = NULL) {
119
Holder
* holder =
dynamic_cast<
Holder
*
>
(
120
::omni_thread::self()->get_value(
_key
));
121
if
(holder) {
122
if
(holder->
data
)
123
delete
holder->
data
;
124
125
holder->
data
= p;
126
}
else
{
127
holder =
new
Holder
(p);
128
::omni_thread::self()->set_value(
_key
, holder);
129
}
130
};
131
132
private
:
133
class
Holder
:
public
omni_thread::value_t {
134
public
:
135
Holder
(data_type*
data
) : data(data) {};
136
virtual
~Holder
() {
if
(
data
)
delete
(
data
); };
137
data_type*
data
;
138
private
:
139
Holder
(
const
Holder
& other);
140
Holder
&
operator=
(
const
Holder
& other);
141
};
142
143
omni_thread::key_t
_key
;
144
};
145
}
146
}
147
#endif
log4cpp::threading::ThreadLocalDataHolder::operator*
T & operator*() const
Definition:
OmniThreads.hh:91
log4cpp::threading::ThreadLocalDataHolder::Holder::~Holder
virtual ~Holder()
Definition:
OmniThreads.hh:136
log4cpp::threading::ThreadLocalDataHolder::~ThreadLocalDataHolder
~ThreadLocalDataHolder()
Definition:
OmniThreads.hh:65
log4cpp::threading::ThreadLocalDataHolder::data_type
T data_type
Definition:
OmniThreads.hh:60
log4cpp::threading::ThreadLocalDataHolder::Holder
Definition:
OmniThreads.hh:133
log4cpp::threading::ThreadLocalDataHolder::Holder::data
data_type * data
Definition:
OmniThreads.hh:136
log4cpp::threading::ThreadLocalDataHolder::Holder::Holder
Holder(data_type *data)
Definition:
OmniThreads.hh:135
log4cpp::threading::getThreadId
static std::string getThreadId()
Definition:
BoostThreads.hh:22
log4cpp::threading::ThreadLocalDataHolder::Holder::operator=
Holder & operator=(const Holder &other)
log4cpp::threading::ThreadLocalDataHolder::_key
omni_thread::key_t _key
Definition:
OmniThreads.hh:143
Portability.hh
log4cpp::threading::ThreadLocalDataHolder::operator->
T * operator->() const
Definition:
OmniThreads.hh:84
log4cpp::threading::ThreadLocalDataHolder::ThreadLocalDataHolder
ThreadLocalDataHolder()
Definition:
OmniThreads.hh:62
log4cpp::threading::ThreadLocalDataHolder::release
T * release()
Definition:
OmniThreads.hh:99
log4cpp
Definition:
AbortAppender.hh:16
log4cpp::threading::Mutex
boost::mutex Mutex
Definition:
BoostThreads.hh:37
log4cpp::threading::ThreadLocalDataHolder::reset
void reset(T *p=NULL)
Definition:
OmniThreads.hh:118
log4cpp::threading::ScopedLock
boost::mutex::scoped_lock ScopedLock
Definition:
BoostThreads.hh:40
log4cpp::threading::ThreadLocalDataHolder::_key
DWORD _key
Definition:
MSThreads.hh:163
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:14:17