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

Diff for /pegasus/src/Pegasus/Common/Mutex.cpp between version 1.3.14.9 and 1.3.14.10

version 1.3.14.9, 2006/07/31 17:37:18 version 1.3.14.10, 2006/08/01 20:29:59
Line 29 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Brasher (m.brasher@inovadevelopment.com)  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include "Mutex.h" #include "Mutex.h"
Line 61 
Line 59 
 { {
     once(&_once, _init_attr);     once(&_once, _init_attr);
     pthread_mutex_init(&_rep.mutex, &_attr);     pthread_mutex_init(&_rep.mutex, &_attr);
   #if defined(PEGASUS_DEBUG)
     _rep.count = 0;     _rep.count = 0;
   #endif
 } }
  
 Mutex::~Mutex() Mutex::~Mutex()
 { {
     PEGASUS_DEBUG_ASSERT(_magic);     PEGASUS_DEBUG_ASSERT(_magic);
     pthread_mutex_destroy(&_rep.mutex);     pthread_mutex_destroy(&_rep.mutex);
     _rep.count = -1;  
 } }
  
 void Mutex::lock() void Mutex::lock()
Line 78 
Line 77 
     switch (pthread_mutex_lock(&_rep.mutex))     switch (pthread_mutex_lock(&_rep.mutex))
     {     {
         case 0:         case 0:
   #if defined(PEGASUS_DEBUG)
             _rep.count++;             _rep.count++;
   #endif
             break;             break;
  
         case EDEADLK:  
             throw Deadlock(ThreadType());  
   
         default:         default:
             throw WaitFailed(ThreadType());              throw WaitFailed(Threads::self());
     }     }
 } }
  
Line 96 
Line 94 
     switch (pthread_mutex_trylock(&_rep.mutex))     switch (pthread_mutex_trylock(&_rep.mutex))
     {     {
         case 0:         case 0:
   #if defined(PEGASUS_DEBUG)
             _rep.count++;             _rep.count++;
   #endif
             break;             break;
  
         case EBUSY:         case EBUSY:
             throw AlreadyLocked(ThreadType());              throw AlreadyLocked(Threads::self());
   
         case EDEADLK:  
             throw Deadlock(ThreadType());  
  
         default:         default:
             throw WaitFailed(ThreadType());              throw WaitFailed(Threads::self());
     }     }
 } }
  
Line 132 
Line 129 
         switch (pthread_mutex_trylock(&_rep.mutex))         switch (pthread_mutex_trylock(&_rep.mutex))
         {         {
             case 0:             case 0:
   #if defined(PEGASUS_DEBUG)
                 _rep.count++;                 _rep.count++;
   #endif
                 return;                 return;
  
             case EBUSY:             case EBUSY:
Line 146 
Line 145 
                 break;                 break;
             }             }
  
             case EDEADLK:  
                 throw Deadlock(Threads::self());  
   
             default:             default:
                 throw WaitFailed(Threads::self());                 throw WaitFailed(Threads::self());
         }         }
Line 160 
Line 156 
     PEGASUS_DEBUG_ASSERT(_magic);     PEGASUS_DEBUG_ASSERT(_magic);
     PEGASUS_DEBUG_ASSERT(_rep.count > 0);     PEGASUS_DEBUG_ASSERT(_rep.count > 0);
  
     if (pthread_mutex_unlock(&_rep.mutex) != 0)  #if defined(PEGASUS_DEBUG)
         throw Permission(ThreadType());  
   
     _rep.count--;     _rep.count--;
   #endif
   
       if (pthread_mutex_unlock(&_rep.mutex) != 0)
           throw Permission(Threads::self());
 } }
  
 #endif /* PEGASUS_HAVE_PTHREADS */ #endif /* PEGASUS_HAVE_PTHREADS */
Line 179 
Line 177 
 Mutex::Mutex() Mutex::Mutex()
 { {
     _rep.handle = CreateMutex(NULL, FALSE, NULL);     _rep.handle = CreateMutex(NULL, FALSE, NULL);
     Threads::clear(ThreadType());  #if defined(PEGASUS_DEBUG)
     _rep.count = 0;     _rep.count = 0;
   #endif
 } }
  
 Mutex::~Mutex() Mutex::~Mutex()
Line 198 
Line 197 
     DWORD rc = WaitForSingleObject(_rep.handle, INFINITE);     DWORD rc = WaitForSingleObject(_rep.handle, INFINITE);
  
     if (rc == WAIT_FAILED)     if (rc == WAIT_FAILED)
         throw WaitFailed(ThreadType());          throw WaitFailed(Threads::self());
  
   #if defined(PEGASUS_DEBUG)
     _rep.count++;     _rep.count++;
   #endif
 } }
  
 void Mutex::try_lock() void Mutex::try_lock()
Line 210 
Line 211 
     DWORD rc = WaitForSingleObject(_rep.handle, 0);     DWORD rc = WaitForSingleObject(_rep.handle, 0);
  
     if (rc == WAIT_TIMEOUT)     if (rc == WAIT_TIMEOUT)
         throw AlreadyLocked(ThreadType());          throw AlreadyLocked(Threads::self());
  
     if (rc == WAIT_FAILED)     if (rc == WAIT_FAILED)
         throw WaitFailed(ThreadType());          throw WaitFailed(Threads::self());
  
   #if defined(PEGASUS_DEBUG)
     _rep.count++;     _rep.count++;
   #endif
 } }
  
 void Mutex::timed_lock(Uint32 milliseconds) void Mutex::timed_lock(Uint32 milliseconds)
Line 225 
Line 228 
     DWORD rc = WaitForSingleObject(_rep.handle, milliseconds);     DWORD rc = WaitForSingleObject(_rep.handle, milliseconds);
  
     if (rc == WAIT_TIMEOUT)     if (rc == WAIT_TIMEOUT)
         throw TimeOut(ThreadType());          throw TimeOut(Threads::self());
  
     if (rc == WAIT_FAILED)     if (rc == WAIT_FAILED)
         throw WaitFailed(ThreadType());          throw WaitFailed(Threads::self());
  
   #if defined(PEGASUS_DEBUG)
     _rep.count++;     _rep.count++;
   #endif
 } }
  
 void Mutex::unlock() void Mutex::unlock()
 { {
     PEGASUS_DEBUG_ASSERT(_magic);     PEGASUS_DEBUG_ASSERT(_magic);
       PEGASUS_DEBUG_ASSERT(_rep.count > 0);
  
     Threads::clear(ThreadType());  #if defined(PEGASUS_DEBUG)
     _rep.count--;     _rep.count--;
   #endif
     ReleaseMutex(_rep.handle);     ReleaseMutex(_rep.handle);
 } }
  


Legend:
Removed from v.1.3.14.9  
changed lines
  Added in v.1.3.14.10

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2