PTLib
Version 2.10.4
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
syncthrd.h
Go to the documentation of this file.
1
/*
2
* syncthrd.h
3
*
4
* Various thread synchronisation classes.
5
*
6
* Portable Tools Library
7
*
8
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9
*
10
* The contents of this file are subject to the Mozilla Public License
11
* Version 1.0 (the "License"); you may not use this file except in
12
* compliance with the License. You may obtain a copy of the License at
13
* http://www.mozilla.org/MPL/
14
*
15
* Software distributed under the License is distributed on an "AS IS"
16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17
* the License for the specific language governing rights and limitations
18
* under the License.
19
*
20
* The Original Code is Portable Windows Library.
21
*
22
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23
*
24
* Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25
* All Rights Reserved.
26
*
27
* Contributor(s): ______________________________________.
28
*
29
* $Revision: 26203 $
30
* $Author: rjongbloed $
31
* $Date: 2011-07-14 23:36:07 -0500 (Thu, 14 Jul 2011) $
32
*/
33
34
#ifndef PTLIB_SYNCTHRD_H
35
#define PTLIB_SYNCTHRD_H
36
37
#ifdef P_USE_PRAGMA
38
#pragma interface
39
#endif
40
41
#include <
ptlib/mutex.h
>
42
#include <
ptlib/syncpoint.h
>
43
#include <map>
44
45
67
class
PSyncPointAck
:
public
PSyncPoint
68
{
69
PCLASSINFO(
PSyncPointAck
,
PSyncPoint
);
70
71
public
:
83
virtual
void
Signal
();
84
void
Signal
(
const
PTimeInterval
& waitTime);
85
91
void
Acknowledge
();
92
93
protected
:
94
PSyncPoint
ack
;
95
};
96
97
103
class
PCondMutex
:
public
PMutex
104
{
105
PCLASSINFO(
PCondMutex
,
PMutex
);
106
107
public
:
112
virtual
void
WaitCondition
();
113
118
virtual
void
Signal
();
119
123
virtual
PBoolean
Condition
() = 0;
124
129
virtual
void
OnWait
();
130
131
protected
:
132
PSyncPoint
syncPoint
;
133
};
134
135
138
class
PIntCondMutex
:
public
PCondMutex
139
{
140
PCLASSINFO(
PIntCondMutex
,
PCondMutex
);
141
142
public
:
145
146
enum
Operation
{
148
LT
,
150
LE
,
152
EQ
,
154
GE
,
156
GT
157
};
158
162
PIntCondMutex
(
163
int
value
= 0,
164
int
target
= 0,
165
Operation
operation
=
LE
166
);
168
174
void
PrintOn
(ostream & strm)
const
;
176
184
virtual
PBoolean
Condition
();
185
189
operator
int()
const
{
return
value
; }
190
198
PIntCondMutex
&
operator=
(
int
newval);
199
207
PIntCondMutex
&
operator++
();
208
216
PIntCondMutex
&
operator+=
(
int
inc);
217
225
PIntCondMutex
&
operator--
();
226
234
PIntCondMutex
&
operator-=
(
int
dec);
236
237
238
protected
:
239
int
value
,
target
;
240
Operation
operation
;
241
};
242
243
251
class
PReadWriteMutex
:
public
PObject
252
{
253
PCLASSINFO(
PReadWriteMutex
,
PObject
);
254
public
:
257
PReadWriteMutex
();
258
~PReadWriteMutex
();
260
267
void
StartRead
();
268
271
void
EndRead
();
272
288
void
StartWrite
();
289
301
void
EndWrite
();
303
304
protected
:
305
PSemaphore
readerSemaphore
;
306
PMutex
readerMutex
;
307
unsigned
readerCount
;
308
PMutex
starvationPreventer
;
309
310
PSemaphore
writerSemaphore
;
311
PMutex
writerMutex
;
312
unsigned
writerCount
;
313
314
class
Nest
:
public
PObject
315
{
316
PCLASSINFO(
Nest
,
PObject
);
317
Nest
() { readerCount = writerCount = 0; }
318
unsigned
readerCount;
319
unsigned
writerCount;
320
};
321
typedef
std::map<PThreadIdentifier, Nest>
NestMap
;
322
NestMap
m_nestedThreads
;
323
PMutex
m_nestingMutex
;
324
325
Nest
*
GetNest
();
326
Nest
&
StartNest
();
327
void
EndNest
();
328
void
InternalStartRead
();
329
void
InternalEndRead
();
330
void
InternalWait
(
PSemaphore
& semaphore)
const
;
331
};
332
333
351
class
PReadWaitAndSignal
{
352
public
:
357
PReadWaitAndSignal
(
358
const
PReadWriteMutex
& rw,
359
PBoolean
start =
true
360
);
365
~PReadWaitAndSignal
();
366
367
protected
:
368
PReadWriteMutex
&
mutex
;
369
};
370
371
389
class
PWriteWaitAndSignal
{
390
public
:
395
PWriteWaitAndSignal
(
396
const
PReadWriteMutex
& rw,
397
PBoolean
start =
true
398
);
403
~PWriteWaitAndSignal
();
404
405
protected
:
406
PReadWriteMutex
&
mutex
;
407
};
408
409
410
#endif // PTLIB_SYNCTHRD_H
411
412
413
// End Of File ///////////////////////////////////////////////////////////////
include
ptlib
syncthrd.h
Generated on Tue Mar 11 2014 15:09:30 for PTLib by
1.8.1.2