#ifndef CCDOM_RWMUTEX_H_ #define CCDOM_RWMUTEX_H_ #include #include namespace CCDom { //! Private implemetation object struct RwMutexImpl; //! Read-write mutex class RwMutex { public: //! Private implementation object struct WriteLockImpl; class Lock { public: //! Attempt to obtain a read lock //! This read lock can be promoted to a write lock using the RwMutexWriteLock object //! @throws MutexException if a lock cannot be obtained Lock(RwMutex& m_rwMutex, const boost::xtime& timeout); //! Virtual destructor removes the lock from the mutex virtual ~Lock(); private: RwMutex& m_rwMutex; friend struct WriteLockImpl; // Copy construction and assignment not allowed Lock(const Lock&); Lock& operator=(const Lock&); }; class WriteLock { public: //! Attempt to obtain a write lock by promoting the given (read) lock //! @throws MutexException if a lock cannot be obtained WriteLock(Lock& lock, const boost::xtime& timeout); //! Virtual destructor removes the write lock virtual ~WriteLock(); private: std::auto_ptr m_impl; // Assignment and copy not allowed WriteLock(const WriteLock&); WriteLock& operator=(const WriteLock&); }; //! Constructor RwMutex(); //! Virtual destructor virtual ~RwMutex(); private: std::auto_ptr m_impl; // Copy and assignemnt not allowed RwMutex(const RwMutex&); RwMutex& operator=(const RwMutex&); }; } #endif