(file) Return to Mutex.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/Mutex.h between version 1.4.2.6 and 1.4.2.7

version 1.4.2.6, 2006/07/30 22:57:19 version 1.4.2.7, 2006/07/30 23:11:55
Line 52 
Line 52 
  
 #if defined(PEGASUS_HAVE_PTHREADS) #if defined(PEGASUS_HAVE_PTHREADS)
 typedef pthread_mutex_t MutexType; typedef pthread_mutex_t MutexType;
   inline void mutex_lock(MutexType* mutex) { pthread_mutex_lock(mutex); }
   inline void mutex_unlock(MutexType* mutex) { pthread_mutex_unlock(mutex); }
 struct MutexRep struct MutexRep
 { {
     MutexType mutex;      pthread_mutex_t mutex;
 }; };
 inline void mutex_lock(MutexType* mutex) { pthread_mutex_lock(mutex); }  
 inline void mutex_unlock(MutexType* mutex) { pthread_mutex_unlock(mutex); }  
 # define PEGASUS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER # define PEGASUS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
 #endif #endif
  
 #if defined(PEGASUS_HAVE_WINDOWS_THREADS) #if defined(PEGASUS_HAVE_WINDOWS_THREADS)
 typedef HANDLE MutexType; typedef HANDLE MutexType;
   inline void mutex_lock(MutexType* m) { WaitForSingleObject(*m, INFINITE); }
   inline void mutex_unlock(MutexType* m) { ReleaseMutex(*m); }
 struct MutexRep struct MutexRep
 { {
     MutexType handle;     MutexType handle;
       size_t count;
 }; };
 inline void mutex_lock(MutexType* m) { WaitForSingleObject(*m, INFINITE); }  
 inline void mutex_unlock(MutexType* m) { ReleaseMutex(*m); }  
 # define PEGASUS_MUTEX_INITIALIZER (CreateMutex(NULL, FALSE, NULL)) # define PEGASUS_MUTEX_INITIALIZER (CreateMutex(NULL, FALSE, NULL))
 #endif #endif
  
Line 86 
Line 87 
  
     ~Mutex();     ~Mutex();
  
     void lock()      void lock();
     {  
         mutex_lock(&_rep.mutex);  
     }  
  
     void try_lock();     void try_lock();
  
     void timed_lock(Uint32 milliseconds);     void timed_lock(Uint32 milliseconds);
  
     void unlock()      void unlock();
     {  
         mutex_unlock(&_rep.mutex);  
     }  
  
 private: private:
     Mutex(const Mutex&);     Mutex(const Mutex&);
     Mutex& operator=(const Mutex&);     Mutex& operator=(const Mutex&);
  
   
     MutexRep _rep;     MutexRep _rep;
     Magic<0x57D11485> _magic;     Magic<0x57D11485> _magic;
  
Line 121 
Line 115 
 { {
 public: public:
  
     AutoMutex(Mutex& mutex) : _mutex(mutex)      AutoMutex(Mutex& mutex, Boolean autoLock = true) :
           _mutex(mutex), _locked(autoLock)
     {     {
           if (autoLock)
         _mutex.lock();         _mutex.lock();
     }     }
  
     ~AutoMutex()     ~AutoMutex()
     {     {
         _mutex.unlock();          try
           {
               if (_locked)
                   unlock();
           }
           catch (...)
           {
               // Do not propagate exception from destructor
           }
     }     }
  
     void lock()     void lock()
     {     {
           if (_locked)
               throw AlreadyLocked(ThreadType());
   
         _mutex.lock();         _mutex.lock();
           _locked = true;
     }     }
  
     void unlock()     void unlock()
     {     {
           if (!_locked)
               throw Permission(ThreadType());
   
         _mutex.unlock();         _mutex.unlock();
           _locked = false;
       }
   
       Boolean isLocked() const
       {
           return _locked;
     }     }
  
 private: private:
     AutoMutex();      AutoMutex(); // Unimplemented
     AutoMutex(const AutoMutex& x);      AutoMutex(const AutoMutex& x); // Unimplemented
     AutoMutex& operator=(const AutoMutex& x);      AutoMutex& operator=(const AutoMutex& x); // Unimplemented
  
     Mutex& _mutex;     Mutex& _mutex;
       Boolean _locked;
 }; };
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.4.2.6  
changed lines
  Added in v.1.4.2.7

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2