(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.19 and 1.20

version 1.19, 2013/02/18 15:00:21 version 1.20, 2015/04/23 13:27:57
Line 150 
Line 150 
  
 Boolean Mutex::timed_lock(Uint32 milliseconds) Boolean Mutex::timed_lock(Uint32 milliseconds)
 { {
     struct timeval now;  #ifdef PEGASUS_POSIX_TIMED_LOCK
     struct timeval finish;      struct timespec finish_ns;
     struct timeval remaining;      clock_gettime(CLOCK_REALTIME, &finish_ns);
       finish_ns.tv_sec += (milliseconds / 1000 );
       milliseconds %= 1000;
       Uint32 nsec = finish_ns.tv_nsec + milliseconds * 1000 * 1000;
       finish_ns.tv_sec += (nsec / 1000000000);
       finish_ns.tv_nsec = nsec % 1000000000;
       int r = pthread_mutex_timedlock(&_rep.mutex, &finish_ns);
   
       if (r == 0)
       {
   #if defined(PEGASUS_DEBUG)
           _rep.count++;
   #endif
           return true;
       }
       if (r != -1)
     {     {
         Uint32 usec;          // Special behavior for Single UNIX Specification, Version 3
           errno = r;
       }
       if (errno == EBUSY || errno == ETIMEDOUT)
       {
           return false;
       }
       throw Exception(MessageLoaderParms(
               MUTEX_LOCK_FAILED_KEY,
               MUTEX_LOCK_FAILED_MSG,
               PEGASUS_SYSTEM_ERRORMSG_NLS));
   
   #else // no PEGASUS_POSIX_TIMED_LOCK
   
       struct timeval finish;
   
         gettimeofday(&finish, NULL);         gettimeofday(&finish, NULL);
         finish.tv_sec += (milliseconds / 1000 );         finish.tv_sec += (milliseconds / 1000 );
         milliseconds %= 1000;         milliseconds %= 1000;
         usec = finish.tv_usec + ( milliseconds * 1000 );      Uint32 usec = finish.tv_usec + ( milliseconds * 1000 );
         finish.tv_sec += (usec / 1000000);         finish.tv_sec += (usec / 1000000);
         finish.tv_usec = usec % 1000000;         finish.tv_usec = usec % 1000000;
     }  
  
       struct timeval now;
       struct timeval remaining;
     while (!try_lock())     while (!try_lock())
     {     {
         gettimeofday(&now, NULL);         gettimeofday(&now, NULL);
Line 174 
Line 205 
  
         Threads::yield();         Threads::yield();
     }     }
   
     return true;     return true;
   #endif
 } }
  
 void Mutex::unlock() void Mutex::unlock()


Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2