//  // // ##### #### # # -= Threadux =-  // //  # # # ## ## Mutex.h  // //  # # # ##  // //  # # # ### Synchronizes thread access to mutually exclusive code sections  // //  # # # ## ##  // //  # #### # # R1 2004 by Markus Ewald  // //  // #ifndef THREADUX_MUTEX_H #define THREADUX_MUTEX_H #include "Threadux/Threadux.h" #include #include namespace Threadux { //  // //  Threadux::Mutex  // //  // /// Mutex class Mutex { 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) {} }; class ScopedUser; /// Constructor Mutex(); /// Destructor ~Mutex(); private: struct Impl; Mutex(const Mutex &); void operator =(const Mutex &); Impl *m_pImpl; protected: friend ScopedUser; Impl *getImpl() { return m_pImpl; } }; //  // //  Threadux::Mutex  // //  // /// Scoped mutex user class Mutex::ScopedUser { public: /// Constructor ScopedUser(Mutex &TheMutex, size_t Timeout = InfiniteTimeout); /// Constructor ScopedUser(Mutex *TheMutexes, size_t Count, size_t Timeout = InfiniteTimeout); /// Destructor ~ScopedUser() { leave(); } // // ScopedUser implementation // public: /// Leave mutex void leave(); private: ScopedUser(const ScopedUser &); void operator =(const ScopedUser &); /// The mutexes we're working with Mutex *m_pMutexes; /// Number of mutexes size_t m_Count; /// Whether the mutexes have been left already bool m_bLeft; }; } // namespace Threadux; #endif // THREADUX_MUTEX_H