Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Guard.h

Go to the documentation of this file.
00001 #ifndef __GUARD_H
00002 #define __GUARD_H
00003 
00004 class Guard
00005 {
00006 public:
00007         Guard(pthread_mutex_t* mutex)
00008         {
00009         m_mutexObject = NULL;
00010                 m_mutexRaw = mutex;
00011                 pthread_mutex_lock(mutex);
00012         }
00013 
00014     Guard(Mutex* mutex) {
00015         m_mutexRaw = NULL;
00016         m_mutexObject = mutex;
00017         mutex->lock();
00018     }
00019 
00020         ~Guard()
00021         {
00022         if (m_mutexRaw != NULL) {
00023                     pthread_mutex_unlock(m_mutexRaw);
00024         }
00025         else if (m_mutexObject != NULL) {
00026             m_mutexObject->unlock();
00027         }
00028         }
00029 
00030 private:
00031         pthread_mutex_t* m_mutexRaw;
00032     Mutex* m_mutexObject;
00033 };
00034 
00035 #endif

Generated at Thu Jul 11 13:31:50 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001