Synch.h
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //  (c) 2006 by Basler Vision Technologies
00003 //  Section: Vision Components
00004 //  Project: GenApi
00005 //  Author:  Hartmut Nebelung
00006 //  $Header$
00007 //
00008 //  License: This file is published under the license of the EMVA GenICam  Standard Group.
00009 //  A text file describing the legal terms is included in  your installation as 'GenICam_license.pdf'.
00010 //  If for some reason you are missing  this file please contact the EMVA or visit the website
00011 //  (http://www.genicam.org) for a full copy.
00012 //
00013 //  THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
00014 //  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00015 //  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00016 //  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD  GROUP
00017 //  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  SPECIAL,
00018 //  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  LIMITED TO,
00019 //  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  DATA, OR PROFITS;
00020 //  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  THEORY OF LIABILITY,
00021 //  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)
00022 //  ARISING IN ANY WAY OUT OF THE USE  OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00023 //  POSSIBILITY OF SUCH DAMAGE.
00024 //-----------------------------------------------------------------------------
00031 #ifndef GENAPI_SYNCH_H
00032 #define GENAPI_SYNCH_H
00033 
00034 #include <GenApi/GenApiDll.h>
00035 #include <Base/GCException.h>
00036 
00037 #if defined (_WIN32)
00038 #   include <windows.h>
00039 #   include <winbase.h>
00040 #elif defined (__GNUC__) && (defined (__linux__) || defined (__APPLE__))
00041 #   include <pthread.h>
00042 #   include <errno.h>
00043 #   include <list>
00044 #elif defined(VXWORKS)
00045    #include <vxworks.h>
00046    #include <intLib.h>
00047    #include <taskLib.h>
00048 #else
00049 #   error No/unknown platform thread support
00050 #endif
00051 
00052 namespace GENAPI_NAMESPACE
00053 {
00054 
00055     //-----------------------------------------------------------------
00056     // CLock
00057     //-----------------------------------------------------------------
00058 
00063     class GENAPI_DECL CLock
00064     {
00065     public:
00067         CLock();
00068 
00070         ~CLock();
00071 
00073         bool TryLock();
00074 
00076         void Lock();
00077 
00079         void Unlock();
00080 
00081     private:
00083         CLock( const CLock& );
00084 
00086         CLock& operator=( const CLock& );
00087 
00088     protected:
00089 
00090 #if defined (_WIN32)
00091 
00092         CRITICAL_SECTION m_csObject;
00093 #elif defined (__GNUC__) && (defined (__linux__) || defined (__APPLE__))
00094 
00095         pthread_mutex_t m_mtxObject;
00096 #elif defined(VXWORKS)
00097         SEM_ID m_sem;
00098 #else
00099 #       error No/unknown platform thread support
00100 #endif
00101 
00102     };
00103 
00104 
00108     class GENAPI_DECL CLockEx : public CLock
00109     {
00110     public:
00111 
00112 #       if defined (_WIN32)
00113 
00115             int64_t GetLockCount();
00116 
00118             int64_t GetRecursionCount();
00119 
00120 #       elif defined (__GNUC__) && (defined (__linux__) || defined (__APPLE__) || defined(VXWORKS))
00121             // nothing implemented for Unix
00122 #       else
00123 #           error No/unknown platform support
00124 #       endif
00125 
00126     private:
00128         CLockEx( const CLockEx& );
00129 
00131         CLockEx& operator=( const CLockEx& );
00132 
00133     };
00134 
00135 
00136     //-----------------------------------------------------------------
00137     // AutoLock
00138     //-----------------------------------------------------------------
00139     class AutoLock
00140     {
00141         CLock& m_Lock;
00142     public:
00143         AutoLock(CLock& lock)
00144             : m_Lock(lock)
00145         {
00146             m_Lock.Lock();
00147         }
00148 
00149         ~AutoLock()
00150         {
00151             m_Lock.Unlock();
00152         }
00153 
00154     private:
00155         AutoLock& operator=(const AutoLock&);
00156         AutoLock(const AutoLock&);
00157     };
00158 
00159 
00160     //-----------------------------------------------------------------
00161     // template LockableObject<Object,ThreadingModel>
00162     //-----------------------------------------------------------------
00163 
00168     template< class Object>
00169     class LockableObject
00170     {
00171     public:
00172         mutable CLock m_Lock;
00173 
00174         class Lock;
00175         friend class Lock;
00176 
00181         class Lock
00182         {
00184             const LockableObject<Object> &m_Object;
00185         public:
00186             Lock( const LockableObject<Object>& obj) : m_Object(obj) {
00187                 m_Object.m_Lock.Lock();
00188             }
00189 
00190             ~Lock(){
00191                 m_Object.m_Lock.Unlock();
00192             }
00193         private:
00194             Lock& operator=( const Lock& );
00195         };
00196 
00198         Lock GetLock() const
00199         {
00200             return Lock( *this );
00201         }
00202     };
00203 
00204 } // namespace GenApi
00205 
00206 #endif // GENAPI_SYNCH_H


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:06