All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSThreads.hh
Go to the documentation of this file.
1 /*
2  * MSThreads.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_MSTHREADS_HH
11 #define _LOG4CPP_THREADING_MSTHREADS_HH
12 
13 #include <string>
14 
15 // deal with ERROR #define
16 // N.B. This #includes windows.h with NOGDI and WIN32_LEAN_AND_MEAN #defined.
17 // If this is not what the user wants, #include windows.h before this file.
18 #ifndef _WINDOWS_
19 # ifndef NOGDI
20 # define NOGDI // this will circumvent the ERROR #define in windows.h
21 # define LOG4CPP_UNDEFINE_NOGDI
22 # endif
23 
24 # ifndef WIN32_LEAN_AND_MEAN
25 # define WIN32_LEAN_AND_MEAN
26 # define LOG4CPP_UNDEFINE_WIN32_LEAN_AND_MEAN
27 # endif
28 
29 # include <windows.h>
30 
31 # ifdef LOG4CPP_UNDEFINE_NOGDI
32 # undef NOGDI
33 # endif
34 
35 # ifdef LOG4CPP_UNDEFINE_WIN32_LEAN_AND_MEAN
36 # undef WIN32_LEAN_AND_MEAN
37 # endif
38 
39 #endif // done dealing with ERROR #define
40 
42 namespace threading {
48  std::string getThreadId();
49 
54  public:
55  MSMutex() { InitializeCriticalSection(&_criticalSection); }
56  ~MSMutex() { DeleteCriticalSection(&_criticalSection); }
57  inline LPCRITICAL_SECTION getCriticalSection() {
58  return &_criticalSection;
59  }
60 
61  private:
62  MSMutex(const MSMutex& other);
63  CRITICAL_SECTION _criticalSection;
64  };
65 
69  typedef MSMutex Mutex;
70 
75  class MSScopedLock {
76  public:
79  EnterCriticalSection(_criticalSection);
80  }
81 
82  ~MSScopedLock() { LeaveCriticalSection(_criticalSection); }
83 
84  private:
85  MSScopedLock(const MSScopedLock& other);
86  LPCRITICAL_SECTION _criticalSection;
87  };
88 
93  typedef MSScopedLock ScopedLock;
94 
101  template<typename T> class ThreadLocalDataHolder {
102  public:
104  _key(TlsAlloc()) {};
105 
107  TlsFree(_key);
108  };
109 
115  inline T* get() const {
116  return (T*)TlsGetValue(_key);
117  };
118 
125  inline T* operator->() const { return get(); };
126 
132  inline T& operator*() const { return *get(); };
133 
140  inline T* release() {
141  T* result = (T*)TlsGetValue(_key);
142  TlsSetValue(_key, NULL);
143  return result;
144  };
145 
152  inline void reset(T* p = NULL) {
153  T* thing = (T*)TlsGetValue(_key);
154  delete thing;
155  TlsSetValue(_key, p);
156  };
157 
158  private:
159  DWORD _key;
160  };
161 }
163 #endif
threading::ThreadLocalDataHolder::_key
DWORD _key
Definition: MSThreads.hh:156
threading::MSScopedLock::~MSScopedLock
~MSScopedLock()
Definition: MSThreads.hh:82
threading::ThreadLocalDataHolder::release
T * release()
Releases the Object held for the current thread.
Definition: MSThreads.hh:140
threading::ScopedLock
boost::mutex::scoped_lock ScopedLock
Dummy type 'int' defintion of ScopedLock;.
Definition: BoostThreads.hh:30
threading::MSScopedLock
A simple object wrapper around WaitForSingleObject() and ReleaseMutex()
Definition: MSThreads.hh:75
threading::ThreadLocalDataHolder::operator*
T & operator*() const
Obtains the Object held for the current thread.
Definition: MSThreads.hh:132
threading::MSMutex::getCriticalSection
LPCRITICAL_SECTION getCriticalSection()
Definition: MSThreads.hh:57
threading::Mutex
boost::mutex Mutex
Dummy type 'int' for Mutex.
Definition: BoostThreads.hh:27
threading::MSMutex
A simple object wrapper around CreateMutex() and DeleteMutex()
Definition: MSThreads.hh:53
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: MSThreads.hh:115
threading::ThreadLocalDataHolder::reset
void reset(T *p=NULL)
Sets a new Object to be held for the current thread.
Definition: MSThreads.hh:152
threading::MSMutex::_criticalSection
CRITICAL_SECTION _criticalSection
Definition: MSThreads.hh:63
threading::ThreadLocalDataHolder::~ThreadLocalDataHolder
~ThreadLocalDataHolder()
Definition: MSThreads.hh:106
threading::MSMutex::~MSMutex
~MSMutex()
Definition: MSThreads.hh:56
LOG4CPP_NS_BEGIN
#define LOG4CPP_NS_BEGIN
Definition: Portability.hh:49
LOG4CPP_NS_END
#define LOG4CPP_NS_END
Definition: Portability.hh:50
LOG4CPP_EXPORT
#define LOG4CPP_EXPORT
Definition: Export.hh:21
threading::ThreadLocalDataHolder::ThreadLocalDataHolder
ThreadLocalDataHolder()
Definition: MSThreads.hh:103
threading
Definition: BoostThreads.hh:21
threading::MSScopedLock::MSScopedLock
MSScopedLock(MSMutex &mutex)
Definition: MSThreads.hh:77
threading::MSScopedLock::_criticalSection
LPCRITICAL_SECTION _criticalSection
Definition: MSThreads.hh:86
threading::MSMutex::MSMutex
MSMutex()
Definition: MSThreads.hh:55
threading::ThreadLocalDataHolder::operator->
T * operator->() const
Obtains the Object held for the current thread.
Definition: MSThreads.hh:125
threading::ThreadLocalDataHolder
This class holds Thread local data of type T, i.e.
Definition: BoostThreads.hh:32


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