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:
78  _criticalSection = mutex.getCriticalSection();
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
A simple object wrapper around CreateMutex() and DeleteMutex()
Definition: MSThreads.hh:53
#define LOG4CPP_NS_END
Definition: Portability.hh:50
MSScopedLock(MSMutex &mutex)
Definition: MSThreads.hh:77
This class holds Thread local data of type T, i.e.
Definition: BoostThreads.hh:32
LPCRITICAL_SECTION _criticalSection
Definition: MSThreads.hh:86
#define LOG4CPP_EXPORT
Definition: Export.hh:21
A simple object wrapper around WaitForSingleObject() and ReleaseMutex()
Definition: MSThreads.hh:75
CRITICAL_SECTION _criticalSection
Definition: MSThreads.hh:63
static std::string getThreadId()
Return an identifier for the current thread.
Definition: BoostThreads.hh:22
boost::mutex Mutex
Dummy type &#39;int&#39; for Mutex.
Definition: BoostThreads.hh:27
boost::mutex::scoped_lock ScopedLock
Dummy type &#39;int&#39; defintion of ScopedLock;.
Definition: BoostThreads.hh:30
T * operator->() const
Obtains the Object held for the current thread.
Definition: MSThreads.hh:125
void reset(T *p=NULL)
Sets a new Object to be held for the current thread.
Definition: MSThreads.hh:152
LPCRITICAL_SECTION getCriticalSection()
Definition: MSThreads.hh:57
T * release()
Releases the Object held for the current thread.
Definition: MSThreads.hh:140
T & operator*() const
Obtains the Object held for the current thread.
Definition: MSThreads.hh:132
#define LOG4CPP_NS_BEGIN
Definition: Portability.hh:49


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 19:10:54