ITK  4.4.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 #ifndef _WIN32_WINNT
28 #define _WIN32_WINNT 0x0400
29 #endif
30 #endif
31 
32 #if defined(ITK_USE_PTHREADS)
33 #include <pthread.h>
34 #elif defined(ITK_USE_WIN32_THREADS)
35 #include "itkWindows.h"
36 #include <winbase.h>
37 #endif
38 
39 
40 namespace itk
41 {
44 #if defined(ITK_USE_PTHREADS)
45 #define ITK_MAX_THREADS 128
46  typedef pthread_mutex_t MutexType;
47  typedef pthread_mutex_t FastMutexType;
48  typedef void *( * ThreadFunctionType )(void *);
49  typedef pthread_t ThreadProcessIDType;
50 #define ITK_THREAD_RETURN_VALUE NULL
51 #define ITK_THREAD_RETURN_TYPE void *
52 
53 
54 #elif defined(ITK_USE_WIN32_THREADS)
55 
56 #define ITK_MAX_THREADS 128
57  typedef HANDLE MutexType;
58  typedef CRITICAL_SECTION FastMutexType;
59  typedef LPTHREAD_START_ROUTINE ThreadFunctionType;
60  typedef HANDLE ThreadProcessIDType;
61 #define ITK_THREAD_RETURN_VALUE 0
62 #define ITK_THREAD_RETURN_TYPE DWORD __stdcall
63 
64 #else
65 
66 #define ITK_MAX_THREADS 1
67  typedef int MutexType;
68  typedef int FastMutexType;
69  typedef void ( *ThreadFunctionType )(void *);
70  typedef int ThreadProcessIDType;
71 #define ITK_THREAD_RETURN_VALUE
72 #define ITK_THREAD_RETURN_TYPE void
73 
74 #endif
75 
78 #if defined(ITK_USE_PTHREADS)
79  typedef struct {
80  pthread_cond_t m_ConditionVariable;
81  } ConditionVariableType;
82 #elif defined(ITK_USE_WIN32_THREADS)
83  typedef struct {
84  int m_NumberOfWaiters; // number of waiting threads
85  CRITICAL_SECTION m_NumberOfWaitersLock; // Serialize access to
86  // m_NumberOfWaiters
88 
89  HANDLE m_Semaphore; // Semaphore to queue threads
90  HANDLE m_WaitersAreDone; // Auto-reset event used by the
91  // broadcast/signal thread to
92  // wait for all the waiting
93  // threads to wake up and
94  // release the semaphore
95 
96  int m_WasBroadcast; // Used as boolean. Keeps track of whether
97  // we were broadcasting or signaling
98  } ConditionVariableType;
99 #else
100  typedef struct { } ConditionVariableType;
101 #endif
102 
103 
104 }
105 #endif
106