ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkThreadSupport.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkThreadSupport_h
19 #define __itkThreadSupport_h
20 
21 
22 // This implementation uses a routine called SignalObjectAndWait()
23 // which is only defined on WinNT 4.0 or greater systems. We need to
24 // define this symbol in order to get the prototype for the
25 // routine. This needs to be done before we load any system headers.
26 #ifdef ITK_USE_WIN32_THREADS
27 #undef _WIN32_WINNT
28 #define _WIN32_WINNT 0x0400
29 #endif
30 
31 #if defined(ITK_USE_PTHREADS)
32 #include <pthread.h>
33 #elif defined(ITK_USE_WIN32_THREADS)
34 #include "itkWindows.h"
35 #include <winbase.h>
36 #endif
37 
38 
39 namespace itk
40 {
43 #if defined(ITK_USE_PTHREADS)
44 #define ITK_MAX_THREADS 128
45  typedef pthread_mutex_t MutexType;
46  typedef pthread_mutex_t FastMutexType;
47  typedef void *( * ThreadFunctionType )(void *);
48  typedef pthread_t ThreadProcessIDType;
49 #define ITK_THREAD_RETURN_VALUE NULL
50 #define ITK_THREAD_RETURN_TYPE void *
51 
52 
53 #elif defined(ITK_USE_WIN32_THREADS)
54 
55 #define ITK_MAX_THREADS 128
56  typedef HANDLE MutexType;
57  typedef CRITICAL_SECTION FastMutexType;
58  typedef LPTHREAD_START_ROUTINE ThreadFunctionType;
59  typedef HANDLE ThreadProcessIDType;
60 #define ITK_THREAD_RETURN_VALUE 0
61 #define ITK_THREAD_RETURN_TYPE DWORD __stdcall
62 
63 #else
64 
65 #define ITK_MAX_THREADS 1
66  typedef int MutexType;
67  typedef int FastMutexType;
68  typedef void ( *ThreadFunctionType )(void *);
69  typedef int ThreadProcessIDType;
70 #define ITK_THREAD_RETURN_VALUE
71 #define ITK_THREAD_RETURN_TYPE void
72 
73 #endif
74 
77 #if defined(ITK_USE_PTHREADS)
78  typedef struct {
79  pthread_cond_t m_ConditionVariable;
80  } ConditionVariableType;
81 #elif defined(ITK_USE_WIN32_THREADS)
82  typedef struct {
83  int m_NumberOfWaiters; // number of waiting threads
84  CRITICAL_SECTION m_NumberOfWaitersLock; // Serialize access to
85  // m_NumberOfWaiters
87 
88  HANDLE m_Semaphore; // Semaphore to queue threads
89  HANDLE m_WaitersAreDone; // Auto-reset event used by the
90  // broadcast/signal thread to
91  // wait for all the waiting
92  // threads to wake up and
93  // release the semaphore
94 
95  int m_WasBroadcast; // Used as boolean. Keeps track of whether
96  // we were broadcasting or signaling
97  } ConditionVariableType;
98 #else
99  typedef struct { } ConditionVariableType;
100 #endif
101 
102 
103 }
104 #endif
105