ML Reference
mlBarrier.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2009, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_BARRIER_H
14#define ML_BARRIER_H
15
18
19#include "mlUtilsSystem.h"
20
21#include "mlMutex.h"
22#include "mlWaitCondition.h"
23
24ML_UTILS_START_NAMESPACE
25
26//----------------------------------------------------------------------------------
30//----------------------------------------------------------------------------------
32
33public:
34 //----------------------------------------------------------------------------------
36 //----------------------------------------------------------------------------------
37 Barrier(unsigned int count = 0);
38
39 //----------------------------------------------------------------------------------
42 //----------------------------------------------------------------------------------
43 void setNumberOfThreads(unsigned int count);
44
45 //----------------------------------------------------------------------------------
48 //----------------------------------------------------------------------------------
49 bool wait();
50
51private:
53 Barrier(const Barrier&);
54 Barrier& operator =(const Barrier&);
55
57 unsigned int _count;
59 unsigned int _generation;
61 unsigned int _numberOfThreads;
62
64 Mutex _mutex;
66 WaitCondition _finishedNotifier;
67};
68
69//----------------------------------------------------------------------------------
78//----------------------------------------------------------------------------------
80
81public:
82 //----------------------------------------------------------------------------------
85 //----------------------------------------------------------------------------------
86 ScopedBarrierWaiter(Barrier& barrier, unsigned int numberOfExpectedWaits = 1);
88
89 //----------------------------------------------------------------------------------
92 //----------------------------------------------------------------------------------
93 void wait();
94
95private:
98 ScopedBarrierWaiter& operator =(const ScopedBarrierWaiter&);
99
101 Barrier& _barrier;
103 unsigned int _numberOfExpectedWaits;
104};
105
106ML_UTILS_END_NAMESPACE
107
108#endif // __mlBarrier_H
109
110
Barrier(unsigned int count=0)
Creates a barrier with initial count of threads to synchronize.
void setNumberOfThreads(unsigned int count)
ScopedBarrierWaiter(Barrier &barrier, unsigned int numberOfExpectedWaits=1)
boost::mutex Mutex
Definition mlMutex.h:39
#define ML_UTILS_EXPORT
Definition mlUtilities.h:18