(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.10 and 1.12

version 1.10, 2008/04/16 07:13:47 version 1.12, 2008/08/15 17:24:52
Line 104 
Line 104 
     }     }
 } }
  
 void Mutex::try_lock()  Boolean Mutex::try_lock()
 { {
     PEGASUS_DEBUG_ASSERT(_magic);     PEGASUS_DEBUG_ASSERT(_magic);
  
     int r = pthread_mutex_trylock(&_rep.mutex);     int r = pthread_mutex_trylock(&_rep.mutex);
     if (r == -1)     if (r == -1)
         r=errno;         r=errno;
     switch (r)  
       if (r == 0)
     {     {
         case 0:  
 #if defined(PEGASUS_DEBUG) #if defined(PEGASUS_DEBUG)
             _rep.count++;             _rep.count++;
 #endif #endif
             break;          return true;
       }
  
         case EBUSY:      if (r == EBUSY)
             throw AlreadyLocked(Threads::self());      {
           return false;
       }
  
         default:  
             throw WaitFailed(Threads::self());             throw WaitFailed(Threads::self());
     }     }
 }  
  
 void Mutex::timed_lock(Uint32 milliseconds)  Boolean Mutex::timed_lock(Uint32 milliseconds)
 { {
     PEGASUS_DEBUG_ASSERT(_magic);     PEGASUS_DEBUG_ASSERT(_magic);
  
Line 149 
Line 150 
         int r=pthread_mutex_trylock(&_rep.mutex);         int r=pthread_mutex_trylock(&_rep.mutex);
         if (r == -1)         if (r == -1)
             r = errno;             r = errno;
         switch (r)  
         {  
             case 0:  
 #if defined(PEGASUS_DEBUG)  
                 _rep.count++;  
 #endif  
                 return;  
  
             case EBUSY:          if (r == 0)
           {
               break;
           }
           else if (r == EBUSY)
             {             {
                 gettimeofday(&now, NULL);                 gettimeofday(&now, NULL);
  
                 if (Time::subtract(&remaining, &finish, &now))                 if (Time::subtract(&remaining, &finish, &now))
                     throw TimeOut(Threads::self());              {
                   return false;
               }
  
                 Threads::yield();                 Threads::yield();
                 break;  
             }             }
           else
             default:          {
                 throw WaitFailed(Threads::self());                 throw WaitFailed(Threads::self());
         }         }
     }     }
   
   #if defined(PEGASUS_DEBUG)
       _rep.count++;
   #endif
       return true;
 } }
  
 void Mutex::unlock() void Mutex::unlock()
Line 249 
Line 253 
     _rep.count++;     _rep.count++;
 } }
  
 void Mutex::try_lock()  Boolean Mutex::try_lock()
 { {
     PEGASUS_DEBUG_ASSERT(_magic);     PEGASUS_DEBUG_ASSERT(_magic);
  
     DWORD rc = WaitForSingleObject(_rep.handle, 0);     DWORD rc = WaitForSingleObject(_rep.handle, 0);
  
     if (rc == WAIT_TIMEOUT)     if (rc == WAIT_TIMEOUT)
         throw AlreadyLocked(Threads::self());      {
           return false;
       }
  
     if (rc == WAIT_FAILED)     if (rc == WAIT_FAILED)
       {
         throw WaitFailed(Threads::self());         throw WaitFailed(Threads::self());
       }
  
     _rep.count++;     _rep.count++;
       return true;
 } }
  
 void Mutex::timed_lock(Uint32 milliseconds)  Boolean Mutex::timed_lock(Uint32 milliseconds)
 { {
     PEGASUS_DEBUG_ASSERT(_magic);     PEGASUS_DEBUG_ASSERT(_magic);
  
     DWORD rc = WaitForSingleObject(_rep.handle, milliseconds);     DWORD rc = WaitForSingleObject(_rep.handle, milliseconds);
  
     if (rc == WAIT_TIMEOUT)     if (rc == WAIT_TIMEOUT)
         throw TimeOut(Threads::self());          return false;
  
     if (rc == WAIT_FAILED)     if (rc == WAIT_FAILED)
         throw WaitFailed(Threads::self());         throw WaitFailed(Threads::self());
  
     _rep.count++;     _rep.count++;
       return true;
 } }
  
 void Mutex::unlock() void Mutex::unlock()


Legend:
Removed from v.1.10  
changed lines
  Added in v.1.12

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2