VTK
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
dox
Common
vtkConditionVariable.h
Go to the documentation of this file.
1
/*=========================================================================
2
3
Program: Visualization Toolkit
4
Module: vtkConditionVariable.h
5
6
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
All rights reserved.
8
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10
This software is distributed WITHOUT ANY WARRANTY; without even
11
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
PURPOSE. See the above copyright notice for more information.
13
14
=========================================================================*/
32
#ifndef __vtkConditionVariable_h
33
#define __vtkConditionVariable_h
34
35
#include "
vtkObject.h
"
36
37
#include "
vtkMutexLock.h
"
// Need for friend access to vtkSimpleMutexLock
38
39
//BTX
40
#if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
41
# include <pthread.h>
// Need POSIX thread implementation of mutex (even win32 provides mutexes)
42
typedef
pthread_cond_t
vtkConditionType
;
43
#endif
44
45
46
// Typically a top level windows application set _WIN32_WINNT. If it is not set we set it to
47
// 0x0500 (Windows 2000) because visual studio 6...
48
#ifdef VTK_USE_WIN32_THREADS
49
# ifndef _WIN32_WINNT
50
# define _WIN32_WINNT 0x0500 // Minimum windows version supported is Windows 2000.
51
# endif
52
# include "vtkWindows.h"
// Needed for win32 CRITICAL_SECTION, HANDLE, etc.
53
#endif
54
55
#ifdef VTK_USE_WIN32_THREADS
56
#if 1
57
typedef
struct
58
{
59
// Number of threads waiting on condition.
60
int
WaitingThreadCount;
61
62
// Lock for WaitingThreadCount
63
CRITICAL_SECTION WaitingThreadCountCritSec;
64
65
// Semaphore to block threads waiting for the condition to change.
66
vtkWindowsHANDLE Semaphore;
67
68
// An event used to wake up thread(s) waiting on the semaphore
69
// when pthread_cond_signal or pthread_cond_broadcast is called.
70
vtkWindowsHANDLE DoneWaiting;
71
72
// Was pthread_cond_broadcast called?
73
size_t
WasBroadcast;
74
} pthread_cond_t;
75
76
typedef
pthread_cond_t
vtkConditionType
;
77
# else // 0
78
typedef
struct
79
{
80
// Number of threads waiting on condition.
81
int
WaitingThreadCount;
82
83
// Lock for WaitingThreadCount
84
CRITICAL_SECTION WaitingThreadCountCritSec;
85
86
// Number of threads to release when pthread_cond_broadcast()
87
// or pthread_cond_signal() is called.
88
int
ReleaseCount;
89
90
// Used to prevent one thread from decrementing ReleaseCount all
91
// by itself instead of letting others respond.
92
int
NotifyCount;
93
94
// A manual-reset event that's used to block and release waiting threads.
95
vtkWindowsHANDLE Event;
96
} pthread_cond_t;
97
98
typedef
pthread_cond_t
vtkConditionType
;
99
# endif // 0
100
#endif // VTK_USE_WIN32_THREADS
101
102
#ifndef VTK_USE_PTHREADS
103
#ifndef VTK_HP_PTHREADS
104
#ifndef VTK_USE_WIN32_THREADS
105
typedef
int
vtkConditionType
;
106
#endif
107
#endif
108
#endif
109
110
// Condition variable that is not a vtkObject.
111
class
VTK_COMMON_EXPORT
vtkSimpleConditionVariable
112
{
113
public
:
114
vtkSimpleConditionVariable
();
115
~
vtkSimpleConditionVariable
();
116
117
static
vtkSimpleConditionVariable
* New();
118
119
void
Delete
() {
delete
this
; }
120
122
void
Signal();
123
125
void
Broadcast();
126
135
int
Wait(
vtkSimpleMutexLock
& mutex );
136
137
protected
:
138
vtkConditionType
ConditionVariable
;
139
};
140
141
//ETX
142
143
class
VTK_COMMON_EXPORT
vtkConditionVariable
:
public
vtkObject
144
{
145
public
:
146
static
vtkConditionVariable
*
New
();
147
vtkTypeMacro(
vtkConditionVariable
,
vtkObject
);
148
void
PrintSelf
( ostream& os,
vtkIndent
indent );
149
151
void
Signal();
152
154
void
Broadcast();
155
164
int
Wait(
vtkMutexLock
* mutex );
165
166
protected
:
167
vtkConditionVariable
() { }
168
169
//BTX
170
vtkSimpleConditionVariable
SimpleConditionVariable
;
171
//ETX
172
173
private
:
174
vtkConditionVariable
(
const
vtkConditionVariable
& );
// Not implemented.
175
void
operator = (
const
vtkConditionVariable
& );
// Not implemented.
176
};
177
178
//BTX
179
inline
void
vtkConditionVariable::Signal
()
180
{
181
this->
SimpleConditionVariable
.
Signal
();
182
}
183
184
inline
void
vtkConditionVariable::Broadcast
()
185
{
186
this->
SimpleConditionVariable
.
Broadcast
();
187
}
188
189
inline
int
vtkConditionVariable::Wait
(
vtkMutexLock
* lock )
190
{
191
return
this->
SimpleConditionVariable
.
Wait
( lock->
SimpleMutexLock
);
192
}
193
//ETX
194
195
#endif // __vtkConditionVariable_h
Generated on Thu Mar 13 2014 08:09:43 for VTK by
1.8.1.2