Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

igtlConditionVariable.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Open IGT Link Library
00004   Module:    $HeadURL: http://svn.na-mic.org/NAMICSandBox/trunk/OpenIGTLink/Source/igtlConditionVariable.h $
00005   Language:  C++
00006   Date:      $Date: 2008-12-22 19:05:42 -0500 (Mon, 22 Dec 2008) $
00007   Version:   $Reivision$
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010 
00011   This software is distributed WITHOUT ANY WARRANTY; without even
00012   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00013   PURPOSE.  See the above copyright notices for more information.
00014 
00015 =========================================================================*/
00016 /*=========================================================================
00017 
00018   Program:   Insight Segmentation & Registration Toolkit
00019   Module:    $RCSfile: itkConditionVariable.h,v $
00020   Language:  C++
00021   Date:      $Date: 2008-12-22 19:05:42 -0500 (Mon, 22 Dec 2008) $
00022   Version:   $Revision: 3460 $
00023 
00024   Copyright (c) Insight Software Consortium. All rights reserved.
00025   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00026 
00027      This software is distributed WITHOUT ANY WARRANTY; without even 
00028      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00029      PURPOSE.  See the above copyright notices for more information.
00030 
00031 =========================================================================*/
00032 #ifndef  __igtlConditionVariable_h
00033 #define  __igtlConditionVariable_h
00034 
00035 #include "igtlConfigure.h"
00036 
00037 // This implementation uses a routine called SignalObjectAndWait()
00038 // which is only defined on WinNT 4.0 or greater systems.  We need to
00039 // define this symbol in order to get the prototype for the
00040 // routine. This needs to be done before we load any system headers.
00041 #ifdef OpenIGTLink_USE_WIN32_THREADS
00042 #undef _WIN32_WINNT
00043 #define _WIN32_WINNT 0x0400
00044 #include "igtlWindows.h"
00045 #endif
00046 
00047 
00048 #include "igtlMutexLock.h"
00049 #include "igtlLightObject.h"
00050 
00051 
00052 namespace igtl {
00053 
00084 class IGTLCommon_EXPORT ConditionVariable : public LightObject
00085 {
00086 public:
00088   typedef ConditionVariable        Self;
00089   typedef LightObject              Superclass;
00090   typedef SmartPointer<Self>       Pointer;
00091   typedef SmartPointer<const Self> ConstPointer;
00092 
00094   igtlNewMacro(Self);
00095 
00097   igtlTypeMacro(ConditionVariable, LightObject);
00098 
00102   void Wait(SimpleMutexLock * mutex);
00103 
00105   void Signal();
00106 
00108   void Broadcast();
00109 
00110 protected:
00111   ConditionVariable();
00112   ~ConditionVariable();
00113 
00114 private:
00115   ConditionVariable(const Self & other);
00116   const Self & operator=( const Self & );
00117 #ifdef OpenIGTLink_USE_PTHREADS
00118   pthread_cond_t m_ConditionVariable;
00119   MutexType      m_Mutex;
00120 #else
00121   int m_NumberOfWaiters;                   // number of waiting threads
00122 #ifdef WIN32
00123   CRITICAL_SECTION m_NumberOfWaitersLock;  // Serialize access to 
00124                                            // m_NumberOfWaiters
00125 
00126   HANDLE m_Semaphore;                      // Semaphore to queue threads 
00127   HANDLE m_WaitersAreDone;                 // Auto-reset event used by the
00128                                            // broadcast/signal thread to
00129                                            // wait for all the waiting
00130                                            // threads to wake up and
00131                                            // release the semaphore
00132 
00133   size_t m_WasBroadcast;                   // Keeps track of whether we
00134                                            // were broadcasting or signaling
00135 #endif
00136 #endif
00137 };
00138 
00139 } // end namespace igtl
00140 
00141 #endif
00142 

Generated at Mon May 2 2011 03:56:12 for OpenIGTLink by doxygen 1.7.3 written by Dimitri van Heesch, © 1997-2000