openscenegraph
Barrier
Go to the documentation of this file.
1/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14
15//
16// Barrier - C++ barrier class
17// ~~~~~~~
18//
19
20#ifndef _OPENTHREADS_BARRIER_
21#define _OPENTHREADS_BARRIER_
22
23#include <OpenThreads/Exports>
24
25namespace OpenThreads {
26
27
28/**
29 * @class Barrier
30 * @brief This class provides an object-oriented thread barrier interface
31 *
32 * @warning It is unwise to use the construct "Barrier barrier" in the
33 * global namespace on sgi's. The object "barrier"
34 * will confilict with the c-library sproc function "barrier" and
35 * unpredictable results may occur. You have been warned.
36 */
37class OPENTHREAD_EXPORT_DIRECTIVE Barrier {
38
39public:
40
41 /**
42 * Constructor
43 */
44 Barrier(int numThreads=0);
45
46 /**
47 * Destructor
48 */
49 virtual ~Barrier();
50
51 /**
52 * Reset the barrier to it's original state.
53 */
54 virtual void reset();
55
56 /**
57 * Block until numThreads threads have entered the barrier.
58 */
59 virtual void block(unsigned int numThreads=0);
60
61 /**
62 * Release the barrier, now.
63 */
64 virtual void release();
65
66 /**
67 * Return the number of threads currently blocked in the barrier,
68 * Return -1 if error.
69 */
70 virtual int numThreadsCurrentlyBlocked();
71
72
73 void invalidate();
74
75private:
76
77 /**
78 * Private copy constructor, to prevent tampering.
79 */
80 Barrier(const Barrier &/*b*/) {};
81
82 /**
83 * Private copy assignment, to prevent tampering.
84 */
85 Barrier &operator=(const Barrier &/*b*/) {return *(this);};
86
87 /**
88 * Implementation-specific private data.
89 */
90 void *_prvData;
91
92
93 bool _valid;
94
95};
96
97}
98
99#endif // !_OPENTHREADS_BARRIER_
100