Synch.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // (c) 2006 by Basler Vision Technologies
3 // Section: Vision Components
4 // Project: GenApi
5 // Author: Hartmut Nebelung
6 // $Header$
7 //
8 // License: This file is published under the license of the EMVA GenICam Standard Group.
9 // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
10 // If for some reason you are missing this file please contact the EMVA or visit the website
11 // (http://www.genicam.org) for a full copy.
12 //
13 // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
14 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
17 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 // POSSIBILITY OF SUCH DAMAGE.
24 //-----------------------------------------------------------------------------
31 #ifndef GENAPI_SYNCH_H
32 #define GENAPI_SYNCH_H
33 
34 #include <GenApi/GenApiDll.h>
35 #include <Base/GCException.h>
36 
37 #if defined (_WIN32)
38 # include <windows.h>
39 # include <winbase.h>
40 #elif defined (__GNUC__) && (defined (__linux__) || defined (__APPLE__))
41 # include <pthread.h>
42 # include <errno.h>
43 # include <list>
44 #elif defined(VXWORKS)
45  #include <vxworks.h>
46  #include <intLib.h>
47  #include <taskLib.h>
48 #else
49 # error No/unknown platform thread support
50 #endif
51 
52 namespace GENAPI_NAMESPACE
53 {
54 
55  //-----------------------------------------------------------------
56  // CLock
57  //-----------------------------------------------------------------
58 
64  {
65  public:
67  CLock();
68 
70  ~CLock();
71 
73  bool TryLock();
74 
76  void Lock();
77 
79  void Unlock();
80 
81  private:
83  CLock( const CLock& );
84 
86  CLock& operator=( const CLock& );
87 
88  protected:
89 
90 #if defined (_WIN32)
91  CRITICAL_SECTION m_csObject;
93 #elif defined (__GNUC__) && (defined (__linux__) || defined (__APPLE__))
94  pthread_mutex_t m_mtxObject;
96 #elif defined(VXWORKS)
97  SEM_ID m_sem;
98 #else
99 # error No/unknown platform thread support
100 #endif
101 
102  };
103 
104 
108  class GENAPI_DECL CLockEx : public CLock
109  {
110  public:
111 
112 # if defined (_WIN32)
113 
115  int64_t GetLockCount();
116 
118  int64_t GetRecursionCount();
119 
120 # elif defined (__GNUC__) && (defined (__linux__) || defined (__APPLE__) || defined(VXWORKS))
121  // nothing implemented for Unix
122 # else
123 # error No/unknown platform support
124 # endif
125 
126  private:
128  CLockEx( const CLockEx& );
129 
131  CLockEx& operator=( const CLockEx& );
132 
133  };
134 
135 
136  //-----------------------------------------------------------------
137  // AutoLock
138  //-----------------------------------------------------------------
139  class AutoLock
140  {
142  public:
144  : m_Lock(lock)
145  {
146  m_Lock.Lock();
147  }
148 
150  {
151  m_Lock.Unlock();
152  }
153 
154  private:
155  AutoLock& operator=(const AutoLock&);
156  AutoLock(const AutoLock&);
157  };
158 
159 
160  //-----------------------------------------------------------------
161  // template LockableObject<Object,ThreadingModel>
162  //-----------------------------------------------------------------
163 
168  template< class Object>
170  {
171  public:
172  mutable CLock m_Lock;
173 
174  class Lock;
175  friend class Lock;
176 
181  class Lock
182  {
185  public:
186  Lock( const LockableObject<Object>& obj) : m_Object(obj) {
187  m_Object.m_Lock.Lock();
188  }
189 
190  ~Lock(){
191  m_Object.m_Lock.Unlock();
192  }
193  private:
194  Lock& operator=( const Lock& );
195  };
196 
198  Lock GetLock() const
199  {
200  return Lock( *this );
201  }
202  };
203 
204 } // namespace GenApi
205 
206 #endif // GENAPI_SYNCH_H
Lock(const LockableObject< Object > &obj)
Definition: Synch.h:186
AutoLock(CLock &lock)
Definition: Synch.h:143
virtual void operator=(bool Value)
Set node value.
Definition: IBoolean.h:64
__int64 int64_t
Definition: config-win32.h:21
Lock GetLock() const
Get a new lock.
Definition: Synch.h:198
#define GENAPI_DECL
Definition: GenApiDll.h:55
void Lock()
enters the critical section (may block)
const LockableObject< Object > & m_Object
Reference to outer object.
Definition: Synch.h:184
void Unlock()
leaves the critical section
declspec&#39;s to be used for GenApi Windows dll
This class is for testing purposes only.
Definition: Synch.h:108
Part of the generic device API.
Definition: Autovector.h:48
Instance-Lock for an object.
Definition: Synch.h:169
A lock class.
Definition: Synch.h:63


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