ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkThreadSupport_h 00019 #define __itkThreadSupport_h 00020 00021 00022 // This implementation uses a routine called SignalObjectAndWait() 00023 // which is only defined on WinNT 4.0 or greater systems. We need to 00024 // define this symbol in order to get the prototype for the 00025 // routine. This needs to be done before we load any system headers. 00026 #ifdef ITK_USE_WIN32_THREADS 00027 #undef _WIN32_WINNT 00028 #define _WIN32_WINNT 0x0400 00029 #endif 00030 00031 #if defined(ITK_USE_PTHREADS) 00032 #include <pthread.h> 00033 #elif defined(ITK_USE_WIN32_THREADS) 00034 #include "itkWindows.h" 00035 #include <winbase.h> 00036 #endif 00037 00038 00039 namespace itk 00040 { 00043 #if defined(ITK_USE_PTHREADS) 00044 #define ITK_MAX_THREADS 128 00045 typedef pthread_mutex_t MutexType; 00046 typedef pthread_mutex_t FastMutexType; 00047 typedef void *( * ThreadFunctionType )(void *); 00048 typedef pthread_t ThreadProcessIDType; 00049 #define ITK_THREAD_RETURN_VALUE NULL 00050 #define ITK_THREAD_RETURN_TYPE void * 00051 00052 00053 #elif defined(ITK_USE_WIN32_THREADS) 00054 00055 #define ITK_MAX_THREADS 128 00056 typedef HANDLE MutexType; 00057 typedef CRITICAL_SECTION FastMutexType; 00058 typedef LPTHREAD_START_ROUTINE ThreadFunctionType; 00059 typedef HANDLE ThreadProcessIDType; 00060 #define ITK_THREAD_RETURN_VALUE 0 00061 #define ITK_THREAD_RETURN_TYPE DWORD __stdcall 00062 00063 #else 00064 00065 #define ITK_MAX_THREADS 1 00066 typedef int MutexType; 00067 typedef int FastMutexType; 00068 typedef void ( *ThreadFunctionType )(void *); 00069 typedef int ThreadProcessIDType; 00070 #define ITK_THREAD_RETURN_VALUE 00071 #define ITK_THREAD_RETURN_TYPE void 00072 00073 #endif 00074 00077 #if defined(ITK_USE_PTHREADS) 00078 typedef struct { 00079 pthread_cond_t m_ConditionVariable; 00080 } ConditionVariableType; 00081 #elif defined(ITK_USE_WIN32_THREADS) 00082 typedef struct { 00083 int m_NumberOfWaiters; // number of waiting threads 00084 CRITICAL_SECTION m_NumberOfWaitersLock; // Serialize access to 00085 // m_NumberOfWaiters 00087 00088 HANDLE m_Semaphore; // Semaphore to queue threads 00089 HANDLE m_WaitersAreDone; // Auto-reset event used by the 00090 // broadcast/signal thread to 00091 // wait for all the waiting 00092 // threads to wake up and 00093 // release the semaphore 00094 00095 int m_WasBroadcast; // Used as boolean. Keeps track of whether 00096 // we were broadcasting or signaling 00097 } ConditionVariableType; 00098 #else 00099 typedef struct { } ConditionVariableType; 00100 #endif 00101 00102 00103 } 00104 #endif 00105