// PThreadCondition.h #ifndef dset__PThreadCondition_H #define dset__PThreadCondition_H // Class to hold an integer PThread condition variable and // associated mutex. #include class PThreadCondition { public: // Embedded classes. class Imp; private: // data Imp* pimp; private: // Hide copy and assignment. // Copy. PThreadCondition(const PThreadCondition& rhs); // Assignment. PThreadCondition& operator=(const PThreadCondition& rhs); public: // static methods // Return values. static int ok(); static int invalid_argument(); static int mutex_not_locked(); static int invalid_mutex_lock_count(); static int timed_out(); public: // methods // Constructor. // A new mutex is created. // Predicate is set to zero. PThreadCondition(); // Destructor. ~PThreadCondition(); // Set the variable. // Returns 0 for success. int set(int val); // Retrieve the variable. int get() const; // Signal the condition. // This wakes up one thread waiting on the condition. // Returns 0 for success. int signal(); // Broadcast the condition. // This wakes up all threads waiting on the condition. // Returns 0 for success. int broadcast(); // Wait on the condition. // Mutex must be locked before this is called. // Lock count must be one. // Unlocks mutex while waiting for signal. // Locks mutex before return. // Return values: // ok() // invalid_argument() // mutex_not_locked() // invalid_mutex_lock_count() int wait(); // Wait on the condition for a maximum of dtim seconds. // Mutex must be locked before this is called. // Lock count must be one. // Unlocks mutex while waiting for signal. // Locks mutex before return. // Return values: // ok() // invalid_argument() // mutex_not_locked() // invalid_mutex_lock_count() // timed_out() int wait(unsigned int dtim); // Lock the mutex. int lock(); // Try to lock the mutex. // Returns EBUSY if the mutex is already locked. int trylock(); // Unlock the mutex. int unlock(); // Return the mutex status. bool is_locked() const; // Return the ID of the thread that has locked the mutex. // Returns 0 if the mutex is unlocked. // May return null for a locked mutex if another thread has // not yet completed that operation. #ifndef __CINT__ pthread_t lock_owner() const; #endif }; // Output stream. std::ostream& operator<<(std::ostream& lhs, const PThreadCondition& rhs); #endif