#ifndef LOCK_H_ #define LOCK_H_ #include // has pthread_ routines // ---- Class for lock ----------------------------------------------- // By defining a class for locks, we ensure that pthread_mutex_init // and pthread_mutex_destroy are called automagically (respectively, // when a lockObj is declared and goes out of scope). class lockObj { public: // Constructor (no arguments) and destructor. lockObj(void) { pthread_mutex_init(&theLock, NULL); } ~lockObj(void) { pthread_mutex_destroy(&theLock); } // Function to acquire the lock. void lock(void) { pthread_mutex_lock(&theLock); } // Function to release the lock. void unlock(void) { pthread_mutex_unlock(&theLock); } private: // Make copy constructor and assignment operator private // so they can't be used (since it's not clear this would // make sense). lockObj(const lockObj & d); lockObj & operator= (const lockObj & d); // member variables pthread_mutex_t theLock; }; #endif // LOCK_H_