Changeset 6299

Show
Ignore:
Timestamp:
03/02/07 10:26:55
Author:
robert
Message:

Added handling of overflow from the nano seconds onto second

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenThreads/trunk/pthread_src/PThreadCondition.c++

    r6298 r6299  
    151151        static_cast<PThreadMutexPrivateData *>(mutex->_prvData); 
    152152 
     153 
     154    // wait time is now in ms milliseconds, so need to convert to seconds and nanoseconds for timespec strucuture. 
     155    unsigned int sec = ms / 1000; 
     156    unsigned int nsec = (ms % 1000) * 1000000; 
     157 
     158    // add to the current time     
    153159    struct ::timeval now; 
    154160    ::gettimeofday( &now, 0 ); 
    155161 
    156     // Wait time is now + ms milliseconds 
    157     unsigned int sec = ms / 1000; 
    158     unsigned int nsec = (ms % 1000) * 1000000; 
     162    sec += now.tv_sec; 
     163    nsec += now.tv_usec*1000; 
     164 
     165    // now pass on any overflow from nsec onto seconds. 
     166    sec += nsec / 1000000000; 
     167    nsec = nsec % 1000000000; 
    159168 
    160169    struct timespec abstime; 
    161     abstime.tv_sec = now.tv_sec + sec; 
    162     abstime.tv_nsec = now.tv_usec*1000 + nsec; 
     170    abstime.tv_sec = sec; 
     171    abstime.tv_nsec = nsec; 
    163172 
    164173    int status;