All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
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 
53  _key(omni_thread::allocate_key()) {};
54 
56 
62  inline T* get() const {
63  Holder* holder = dynamic_cast<Holder*>(
64  ::omni_thread::self()->get_value(_key));
65  return (holder) ? holder->data : NULL;
66  };
67 
74  inline T* operator->() const { return get(); };
75 
81  inline T& operator*() const { return *get(); };
82 
89  inline T* release() {
90  T* result = NULL;
91  Holder* holder = dynamic_cast<Holder*>(
92  ::omni_thread::self()->get_value(_key));
93 
94  if (holder) {
95  result = holder->data;
96  holder->data = NULL;
97  }
98 
99  return result;
100  };
101 
108  inline void reset(T* p = NULL) {
109  Holder* holder = dynamic_cast<Holder*>(
110  ::omni_thread::self()->get_value(_key));
111  if (holder) {
112  if (holder->data)
113  delete holder->data;
114 
115  holder->data = p;
116  }
117  else {
118  holder = new Holder(p);
119  ::omni_thread::self()->set_value(_key, holder);
120  }
121  };
122 
123  private:
124  class Holder : public omni_thread::value_t {
125  public:
127  virtual ~Holder() { if (data) delete (data); };
128  data_type* data;
129  private:
130  Holder(const Holder& other);
131  Holder& operator=(const Holder& other);
132  };
133 
134  omni_thread::key_t _key;
135  };
136 }
138 #endif
threading::ThreadLocalDataHolder::Holder::data
data_type * data
Definition: OmniThreads.hh:127
threading::ThreadLocalDataHolder::_key
DWORD _key
Definition: MSThreads.hh:156
threading::ThreadLocalDataHolder::release
T * release()
Releases the Object held for the current thread.
Definition: OmniThreads.hh:89
Portability.hh
threading::ScopedLock
boost::mutex::scoped_lock ScopedLock
Dummy type 'int' defintion of ScopedLock;.
Definition: BoostThreads.hh:30
threading::ThreadLocalDataHolder::data_type
T data_type
Definition: OmniThreads.hh:50
threading::ThreadLocalDataHolder::operator*
T & operator*() const
Obtains the Object held for the current thread.
Definition: OmniThreads.hh:81
threading::Mutex
boost::mutex Mutex
Dummy type 'int' for Mutex.
Definition: BoostThreads.hh:27
threading::ThreadLocalDataHolder::Holder::operator=
Holder & operator=(const Holder &other)
threading::getThreadId
static std::string getThreadId()
Return an identifier for the current thread.
Definition: BoostThreads.hh:22
threading::ThreadLocalDataHolder::get
T * get() const
Obtains the Object held for the current thread.
Definition: OmniThreads.hh:62
threading::ThreadLocalDataHolder::Holder::~Holder
virtual ~Holder()
Definition: OmniThreads.hh:127
threading::ThreadLocalDataHolder::reset
void reset(T *p=NULL)
Sets a new Object to be held for the current thread.
Definition: OmniThreads.hh:108
threading::ThreadLocalDataHolder::~ThreadLocalDataHolder
~ThreadLocalDataHolder()
Definition: OmniThreads.hh:55
threading::ThreadLocalDataHolder::_key
omni_thread::key_t _key
Definition: OmniThreads.hh:134
threading::ThreadLocalDataHolder::Holder::Holder
Holder(data_type *data)
Definition: OmniThreads.hh:126
LOG4CPP_NS_BEGIN
#define LOG4CPP_NS_BEGIN
Definition: Portability.hh:49
LOG4CPP_NS_END
#define LOG4CPP_NS_END
Definition: Portability.hh:50
threading::ThreadLocalDataHolder::ThreadLocalDataHolder
ThreadLocalDataHolder()
Definition: OmniThreads.hh:52
threading
Definition: BoostThreads.hh:21
threading::ThreadLocalDataHolder::Holder
Definition: OmniThreads.hh:124
threading::ThreadLocalDataHolder::operator->
T * operator->() const
Obtains the Object held for the current thread.
Definition: OmniThreads.hh:74


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Dec 4 2024 03:10:11