//  // // ##### #### # # -= Threadux =-  // //  # # # ## ## Gate.h  // //  # # # ##  // //  # # # ### Gate which can be used to halt threads until they are  // //  # # # ## ## allowed to pass  // //  # #### # # R1 2004 by Markus Ewald  // //  // #ifndef THREADUX_GATE_H #define THREADUX_GATE_H #include "Threadux/Threadux.h" #include namespace Threadux { //  // //  Threadux::Gate  // //  // /// Thread gate /** A thread gate blocks passage for any thread until it is opened. This concept is also widely known as event. Gates can also be constructed as watergates, which means they will, when opened, only let a single thread pass through and close again after. Otherwise, all threads "waiting in front of the door" will be allowed to pass once it is opened. */ class Gate { public: /// Fired when a timeout occurs while a thread is using on of the wait functions struct TimeoutError : std::runtime_error { TimeoutError(const std::string &sMessage) : std::runtime_error(sMessage) {} }; /// Constructor explicit Gate(bool bInitiallyOpen = false, bool bWatergate = false); /// Destructor ~Gate(); /// Lets the thread wait until one of the specified gates can be passed static size_t passOneOf(Gate *pFirst, size_t Count, size_t WaitTimeoutMS = 0); /// Lets the thread wait until all of the specified gates can be passed at the same time static void passAllOf(Gate *pFirst, size_t Count, size_t WaitTimeoutMS = 0); // // Gate implementation // public: /// Make the current thread pass through this gate void pass(size_t WaitTimeoutMS = 0); /// Opens the gate to let any waiting threads pass void open(); /// Closes the gate to block any threads trying to pass the gate void close(); private: struct Impl; /// Copy constructor Gate(const Gate &Other); /// Copy assignment operator Gate &operator =(const Gate &Other); /// Implementation details Impl *m_pImpl; }; } // namespace Threadux #endif // THREADUX_GATE_H