ML Reference
|
00001 // **InsertLicense** code 00002 //---------------------------------------------------------------------------------- 00005 00010 //---------------------------------------------------------------------------------- 00011 #ifndef __mlBarrier_H 00012 #define __mlBarrier_H 00013 00014 #ifndef __mlUtilsSystem_H 00015 #include "mlUtilsSystem.h" 00016 #endif 00017 00018 #ifndef __mlMutex_H 00019 #include "mlMutex.h" 00020 #endif 00021 #ifndef __mlWaitCondition_H 00022 #include "mlWaitCondition.h" 00023 #endif 00024 00025 ML_UTILS_START_NAMESPACE 00026 00027 //---------------------------------------------------------------------------------- 00031 //---------------------------------------------------------------------------------- 00032 class ML_UTILS_EXPORT Barrier { 00033 00034 public: 00035 //---------------------------------------------------------------------------------- 00037 //---------------------------------------------------------------------------------- 00038 Barrier(unsigned int count = 0); 00039 00040 //---------------------------------------------------------------------------------- 00043 //---------------------------------------------------------------------------------- 00044 void setNumberOfThreads(unsigned int count); 00045 00046 //---------------------------------------------------------------------------------- 00049 //---------------------------------------------------------------------------------- 00050 bool wait(); 00051 00052 private: 00054 Barrier(const Barrier&); 00055 Barrier& operator =(const Barrier&); 00056 00058 unsigned int _count; 00060 unsigned int _generation; 00062 unsigned int _numberOfThreads; 00063 00065 Mutex _mutex; 00067 WaitCondition _finishedNotifier; 00068 }; 00069 00070 //---------------------------------------------------------------------------------- 00079 //---------------------------------------------------------------------------------- 00080 class ML_UTILS_EXPORT ScopedBarrierWaiter { 00081 00082 public: 00083 //---------------------------------------------------------------------------------- 00086 //---------------------------------------------------------------------------------- 00087 ScopedBarrierWaiter(Barrier& barrier, unsigned int numberOfExpectedWaits = 1); 00088 ~ScopedBarrierWaiter(); 00089 00090 //---------------------------------------------------------------------------------- 00093 //---------------------------------------------------------------------------------- 00094 void wait(); 00095 00096 private: 00098 ScopedBarrierWaiter(const ScopedBarrierWaiter&); 00099 ScopedBarrierWaiter& operator =(const ScopedBarrierWaiter&); 00100 00102 Barrier& _barrier; 00104 unsigned int _numberOfExpectedWaits; 00105 }; 00106 00107 ML_UTILS_END_NAMESPACE 00108 00109 #endif // __mlBarrier_H 00110 00111