OFFIS DCMTK
Version 3.6.0
Main Page
Related Pages
Classes
Files
File List
File Members
ofstd
include
dcmtk
ofstd
ofthread.h
1
/*
2
*
3
* Copyright (C) 1997-2011, OFFIS e.V.
4
* All rights reserved. See COPYRIGHT file for details.
5
*
6
* This software and supporting documentation were developed by
7
*
8
* OFFIS e.V.
9
* R&D Division Health
10
* Escherweg 2
11
* D-26121 Oldenburg, Germany
12
*
13
*
14
* Module: ofstd
15
*
16
* Author: Marco Eichelberg
17
*
18
* Purpose: Provides operating system independent abstractions for basic
19
* multi-thread concepts: threads, thread specific data,
20
* semaphores, mutexes and read/write locks. The implementation
21
* of these classes supports the Solaris, POSIX and Win32
22
* multi-thread APIs.
23
*
24
* Last Update: $Author: onken $
25
* Update Date: $Date: 2011-01-04 14:47:09 $
26
* CVS/RCS Revision: $Revision: 1.12 $
27
* Status: $State: Exp $
28
*
29
* CVS/RCS Log at end of file
30
*
31
*/
32
33
34
#ifndef OFTHREAD_H
35
#define OFTHREAD_H
36
37
#include "dcmtk/config/osconfig.h"
38
#include "dcmtk/ofstd/oftypes.h"
/* for class OFBool */
39
#include "dcmtk/ofstd/ofstring.h"
/* for class OFString */
40
45
extern
"C"
46
{
47
#ifdef HAVE_WINDOWS_H
48
unsigned
int
__stdcall thread_stub(
void
*arg);
49
#else
50
void
*thread_stub(
void
*arg);
51
#endif
52
}
53
54
62
class
OFThread
63
{
64
public
:
65
70
OFThread
();
71
79
virtual
~OFThread
();
80
96
int
start
();
97
107
int
join
();
108
117
unsigned
long
threadID
();
118
124
OFBool
equal
(
unsigned
long
tID);
125
131
static
void
errorstr
(
OFString
& description,
int
code);
132
139
static
const
int
busy
;
140
141
protected
:
142
146
static
void
thread_exit
();
147
157
static
unsigned
long
self
();
158
159
private
:
160
168
virtual
void
run
() = 0;
169
170
#ifdef HAVE_WINDOWS_H
171
172
unsigned
long
theThreadHandle;
173
#endif
174
176
#ifdef HAVE_POINTER_TYPE_PTHREAD_T
177
void
*
theThread
;
178
#else
179
unsigned
long
theThread
;
180
#endif
181
183
OFThread
(
const
OFThread
& arg);
184
186
OFThread
&
operator=
(
const
OFThread
& arg);
187
189
#ifdef HAVE_WINDOWS_H
190
friend
unsigned
int
__stdcall
thread_stub
(
void
*arg);
191
#else
192
friend
void
*
thread_stub
(
void
*arg);
193
#endif
194
};
195
196
206
class
OFThreadSpecificData
207
{
208
public
:
209
211
OFThreadSpecificData
();
212
216
~OFThreadSpecificData
();
217
221
OFBool
initialized
()
const
;
222
229
int
set
(
void
*value);
230
237
int
get
(
void
*&value);
238
244
static
void
errorstr
(
OFString
& description,
int
code);
245
246
private
:
247
249
#ifdef HAVE_CXX_VOLATILE
250
volatile
251
#endif
252
void
*
theKey
;
253
255
OFThreadSpecificData
(
const
OFThreadSpecificData
& arg);
256
258
OFThreadSpecificData
&
operator=
(
const
OFThreadSpecificData
& arg);
259
};
260
261
262
/* Mac OS X only permits named Semaphores. The code below compiles on Mac OS X
263
but does not work. This will be corrected in the next snapshot. For now, the
264
semaphore code is completely disabled for that OS (it is not used in other
265
parts of the toolkit so far.
266
*/
267
#ifndef _DARWIN_C_SOURCE
268
277
class
OFSemaphore
278
{
279
public
:
280
284
OFSemaphore
(
unsigned
int
numResources);
285
287
~OFSemaphore
();
288
292
OFBool
initialized
()
const
;
293
298
int
wait
();
299
305
int
trywait
();
306
311
int
post
();
312
318
static
void
errorstr
(
OFString
& description,
int
code);
319
325
static
const
int
busy
;
326
327
private
:
329
#ifdef HAVE_CXX_VOLATILE
330
volatile
331
#endif
332
void
*
theSemaphore
;
333
335
OFSemaphore
(
const
OFSemaphore
& arg);
336
338
OFSemaphore
&
operator=
(
const
OFSemaphore
& arg);
339
};
340
341
342
#endif // _DARWIN_C_SOURCE
343
352
class
OFMutex
353
{
354
public
:
355
357
OFMutex
();
358
360
~OFMutex
();
361
365
OFBool
initialized
()
const
;
366
373
int
lock
();
374
380
int
trylock
();
381
389
int
unlock
();
390
396
static
void
errorstr
(
OFString
& description,
int
code);
397
403
static
const
int
busy
;
404
405
private
:
407
#ifdef HAVE_CXX_VOLATILE
408
volatile
409
#endif
410
void
*
theMutex
;
411
413
OFMutex
(
const
OFMutex
& arg);
414
416
OFMutex
&
operator=
(
const
OFMutex
& arg);
417
};
418
419
427
class
OFReadWriteLock
428
{
429
public
:
430
432
OFReadWriteLock
();
433
435
~OFReadWriteLock
();
436
440
OFBool
initialized
()
const
;
441
448
int
rdlock
();
449
456
int
wrlock
();
457
463
int
tryrdlock
();
464
470
int
trywrlock
();
471
479
int
unlock
();
480
486
static
void
errorstr
(
OFString
& description,
int
code);
487
493
static
const
int
busy
;
494
495
private
:
497
#ifdef HAVE_CXX_VOLATILE
498
volatile
499
#endif
500
void
*
theLock
;
501
503
OFReadWriteLock
(
const
OFReadWriteLock
& arg);
504
506
OFReadWriteLock
&
operator=
(
const
OFReadWriteLock
& arg);
507
};
508
514
class
OFReadWriteLocker
{
515
public
:
519
OFReadWriteLocker
(
OFReadWriteLock
& lock);
520
522
~OFReadWriteLocker
();
523
528
int
rdlock
();
529
534
int
wrlock
();
535
541
int
tryrdlock
();
542
548
int
trywrlock
();
549
554
int
unlock
();
555
556
private
:
558
OFReadWriteLock
&
theLock
;
559
561
OFBool
locked
;
562
564
OFReadWriteLocker
(
const
OFReadWriteLocker
& arg);
565
567
OFReadWriteLocker
&
operator=
(
const
OFReadWriteLocker
& arg);
568
};
569
570
#endif
571
572
/*
573
*
574
* CVS/RCS Log:
575
* $Log: ofthread.h,v $
576
* Revision 1.12 2011-01-04 14:47:09 onken
577
* Disable and hide OFSemaphore class on Mac OS X since implementation is
578
* broken on that OS (needs named semaphores instead).
579
*
580
* Revision 1.11 2010-10-14 13:15:50 joergr
581
* Updated copyright header. Added reference to COPYRIGHT file.
582
*
583
* Revision 1.10 2010-06-04 13:58:42 uli
584
* Added class OFReadWriteLocker which simplifies unlocking OFReadWriteLocks.
585
*
586
* Revision 1.9 2005-12-08 16:06:08 meichel
587
* Changed include path schema for all DCMTK header files
588
*
589
* Revision 1.8 2004/08/03 16:44:16 meichel
590
* Updated code to correctly handle pthread_t both as an integral integer type
591
* (e.g. Linux, Solaris) and as a pointer type (e.g. BSD, OSF/1).
592
*
593
* Revision 1.7 2003/12/05 10:37:41 joergr
594
* Removed leading underscore characters from preprocessor symbols (reserved
595
* symbols). Updated copyright date where appropriate.
596
*
597
* Revision 1.6 2003/07/04 13:29:51 meichel
598
* Replaced forward declarations for OFString with explicit includes,
599
* needed when compiling with HAVE_STD_STRING
600
*
601
* Revision 1.5 2003/06/06 10:31:04 meichel
602
* Added volatile keyword to data pointers in multi-thread wrapper classes
603
*
604
* Revision 1.4 2002/02/27 14:13:19 meichel
605
* Changed initialized() methods to const. Fixed some return values when
606
* compiled without thread support.
607
*
608
* Revision 1.3 2001/06/01 15:51:36 meichel
609
* Updated copyright header
610
*
611
* Revision 1.2 2000/06/26 09:27:26 joergr
612
* Replaced _WIN32 by HAVE_WINDOWS_H to avoid compiler errors using CygWin-32.
613
*
614
* Revision 1.1 2000/03/29 16:41:23 meichel
615
* Added new classes providing an operating system independent abstraction
616
* for threads, thread specific data, semaphores, mutexes and read/write locks.
617
*
618
*
619
*/
Generated on Thu Dec 20 2012 for
OFFIS DCMTK
Version 3.6.0 by
Doxygen
1.8.2