(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.3.12.1 and 1.8

version 1.3.12.1, 2006/06/29 17:33:12 version 1.8, 2006/09/22 23:12:47
Line 29 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Day (mdday@us.ibm.com)  
 //  
 // Modified By: Markus Mueller  
 //              Ramnath Ravindran (Ramnath.Ravindran@compaq.com)  
 //              David Eger (dteger@us.ibm.com)  
 //              Amit K Arora, IBM (amita@in.ibm.com) for PEP#101  
 //              Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)  
 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)  
 //              David Dillard, VERITAS Software Corp.  
 //                  (david.dillard@veritas.com)  
 //              Aruran, IBM (ashanmug@in.ibm.com) for BUG# 3518  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #ifndef Pegasus_Mutex_h #ifndef Pegasus_Mutex_h
Line 48 
Line 36 
  
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
 #include <Pegasus/Common/Linkage.h> #include <Pegasus/Common/Linkage.h>
 #include <Pegasus/Common/IPCTypes.h>  #include <Pegasus/Common/IPCExceptions.h>
   #include <Pegasus/Common/Magic.h>
   #include <Pegasus/Common/Threads.h>
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
   //==============================================================================
   //
   // MutexRep
   //
   //==============================================================================
   
   #if defined(PEGASUS_HAVE_PTHREADS)
   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
   {
       pthread_mutex_t mutex;
       int count;
   };
   # define PEGASUS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
   #endif
   
   #if defined(PEGASUS_HAVE_WINDOWS_THREADS)
   typedef HANDLE MutexType;
   inline void mutex_lock(MutexType* m) { WaitForSingleObject(*m, INFINITE); }
   inline void mutex_unlock(MutexType* m) { ReleaseMutex(*m); }
   struct MutexRep
   {
       MutexType handle;
       size_t count;
   };
   # define PEGASUS_MUTEX_INITIALIZER (CreateMutex(NULL, FALSE, NULL))
   #endif
   
   //==============================================================================
   //
   // Mutex
   //
   //==============================================================================
   
 class PEGASUS_COMMON_LINKAGE Mutex class PEGASUS_COMMON_LINKAGE Mutex
 { {
 public: public:
  
       enum RecursiveTag { RECURSIVE };
       enum NonRecursiveTag { NON_RECURSIVE };
   
       /** Default constructor creates a recursive mutex.
       */
     Mutex();     Mutex();
     Mutex(int type);  
       /** Call as Mutex(Mutex::RECURSIVE) to create a recursive mutex.
       */
       Mutex(RecursiveTag);
   
       /** Call as Mutex(Mutex::NON_RECURSIVE) to create a non-recursive mutex.
       */
       Mutex(NonRecursiveTag);
  
     ~Mutex();     ~Mutex();
  
     // block until gaining the lock - throw a deadlock      void lock();
     // exception if process already holds the lock  
     // @exception Deadlock  
     // @exception WaitFailed  
     void lock(PEGASUS_THREAD_TYPE caller = pegasus_thread_self());  
   
     // try to gain the lock - lock succeeds immediately if the  
     // mutex is not already locked. throws an exception and returns  
     // immediately if the mutex is currently locked.  
     // @exception Deadlock  
     // @exception AlreadyLocked  
     // @exception WaitFailed  
     void try_lock(PEGASUS_THREAD_TYPE caller = pegasus_thread_self());  
   
     // wait for milliseconds and throw an exception then return if the wait  
     // expires without gaining the lock. Otherwise return without throwing an  
     // exception.  
     // @exception Deadlock  
     // @exception TimeOut  
     // @exception WaitFailed  
     void timed_lock(  
         Uint32 milliseconds,  
         PEGASUS_THREAD_TYPE caller = pegasus_thread_self());  
  
     // unlock the semaphore      void try_lock();
     // @exception Permission  
     void unlock();  
  
     inline PEGASUS_THREAD_TYPE get_owner() { return(_mutex.owner); }      void timed_lock(Uint32 milliseconds);
   
       void unlock();
  
 private: private:
     inline void _set_owner(PEGASUS_THREAD_TYPE owner) { _mutex.owner = owner; }      Mutex(const Mutex&);
     PEGASUS_MUTEX_HANDLE _mutex;      Mutex& operator=(const Mutex&);
     PEGASUS_MUTEX_HANDLE & _get_handle()  
       MutexRep _rep;
       Magic<0x57D11485> _magic;
   
       friend class Condition;
   };
   
   //==============================================================================
   //
   // AutoMutex
   //
   //==============================================================================
   
   class PEGASUS_COMMON_LINKAGE AutoMutex
   {
   public:
   
       AutoMutex(Mutex& mutex) : _mutex(mutex)
     {     {
         return _mutex;          _mutex.lock();
     }     }
  
     // Hide the assignment operator to avoid implicit use of the default      ~AutoMutex()
     // assignment operator.  Do not use this method.      {
     Mutex& operator=(const Mutex& original) {return *this;}          _mutex.unlock();
       }
     // Hide the copy constructor to avoid implicit use of the default  
     // copy constructor.  Do not use this method.  
     Mutex(const Mutex& _mutex);  
  
     friend class Condition;  private:
       AutoMutex(); // Unimplemented
       AutoMutex(const AutoMutex& x); // Unimplemented
       AutoMutex& operator=(const AutoMutex& x); // Unimplemented
   
       Mutex& _mutex;
 }; };
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.3.12.1  
changed lines
  Added in v.1.8

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2