itkSemaphore.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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];
00166 SemaphoreType m_Sema;
00167 char Pad2[128];
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 }
00183
00184 #endif
00185