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

itkSemaphore.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkSemaphore.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-03-03 15:09:14 $
00007   Version:   $Revision: 1.12 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkSemaphore_h
00018 #define __itkSemaphore_h
00019 
00020 #include "itkObjectFactory.h"
00021 #include "itkLightObject.h"
00022 #include "itkConfigure.h"
00023 #include <string>
00024 
00025 #ifdef ITK_USE_UNIX_IPC_SEMAPHORES
00026 #include "itkMutexLock.h"
00027 #include <stdio.h>
00028 #include <sys/types.h>
00029 #include <sys/ipc.h>
00030 #include <sys/sem.h>
00031 #include <errno.h>
00032 #endif
00033 
00034 #ifndef ITK_USE_UNIX_IPC_SEMAPHORES
00035 #ifdef ITK_USE_SPROC
00036 #include "itkMultiThreader.h"
00037 #include <ulocks.h>
00038 #endif
00039 #ifdef ITK_USE_PTHREADS
00040 #ifdef sun
00041 #include <synch.h>
00042 #else
00043 #include <semaphore.h>
00044 #endif
00045 #endif
00046 #endif
00047 
00048 #ifdef ITK_USE_WIN32_THREADS
00049 #include "itkWindows.h"
00050 #endif
00051 
00052 namespace itk {
00053   
00054 #ifdef ITK_USE_UNIX_IPC_SEMAPHORES
00055 typedef int SemaphoreType;
00056 #endif
00057   
00058 #ifndef ITK_USE_UNIX_IPC_SEMAPHORES
00059 #ifdef ITK_USE_SPROC
00060 typedef usema_t * SemaphoreType;
00061 #endif
00062 #ifdef ITK_USE_PTHREADS
00063 #ifdef sun
00064 typedef sema_t SemaphoreType;
00065 #else
00066 #ifdef __APPLE__
00067 typedef sem_t *SemaphoreType;
00068 #else
00069 typedef sem_t  SemaphoreType;
00070 #endif
00071 #endif
00072 #endif
00073 #endif
00074 
00075 #ifdef ITK_USE_WIN32_THREADS
00076 typedef HANDLE SemaphoreType;
00077 #endif
00078 
00079 #ifndef ITK_USE_UNIX_IPC_SEMAPHORES
00080 #ifndef ITK_USE_SPROC
00081 #ifndef ITK_USE_PTHREADS
00082 #ifndef ITK_USE_WIN32_THREADS
00083 typedef int SemaphoreType;
00084 #endif
00085 #endif
00086 #endif
00087 #endif
00088 
00112 class ITKCommon_EXPORT Semaphore : public LightObject
00113 {
00114 public:
00116   typedef Semaphore                 Self;
00117   typedef LightObject               Superclass;
00118   typedef SmartPointer<Self>        Pointer;
00119   typedef SmartPointer<const Self>  ConstPointer;
00120 
00122   itkNewMacro(Self);  
00123 
00125   itkTypeMacro(Semaphore, LightObject);
00126 
00128   void Initialize(unsigned int value);
00129 
00132   void Up();
00133 
00139   void Down();
00140 
00142   void Remove ();
00143 
00144 protected:
00145   Semaphore ();
00146   ~Semaphore();
00147 
00148 private:   
00149 
00150 #ifdef ITK_USE_UNIX_IPC_SEMAPHORES
00151 
00153   static int m_IPCSemaphoreKey;
00154 
00156   static SimpleMutexLock m_Mutex;
00157 
00158   int  UnixIpcSemaphoreCreate (int unix_semaphore_key);
00159   void UnixIpcSemaphoreRemove (int sid);
00160   void UnixIpcSemaphoreCall   (int sid, int op);
00161   void UnixIpcSemaphoreDown   (int sid);
00162   void UnixIpcSemaphoreUp     (int sid);
00163 #endif
00164   
00165   char Pad1[128]; // to avoid false sharing in case of shared memory multiprocessor systems
00166   SemaphoreType m_Sema;
00167   char Pad2[128]; // to avoid false sharing in case of shared memory multiprocessor systems
00168 
00169 #ifdef __APPLE__
00170   std::string GetUniqueName();
00171   static int  m_SemaphoreCount;
00172   std::string m_SemaphoreName;
00173 #endif
00174 
00176 #ifdef ITK_USE_PTHREADS
00177   bool m_PThreadsSemaphoreRemoved;
00178 #endif
00179 
00180 };
00181  
00182 }//itk
00183 
00184 #endif
00185 

Generated at Mon Jul 12 2010 19:48:40 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000