src/os/linux/vm/os_linux.cpp

Print this page
rev 6079 : 8037340: Linux semaphores to use CLOCK_REALTIME
Reviewed-by:

*** 107,116 **** --- 107,118 ---- #define RUSAGE_THREAD (1) /* only the calling thread */ #endif #define MAX_PATH (2 * K) + #define MAX_SECS 100000000 + // for timer info max values which include all bits #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) #define LARGEPAGES_BIT (1 << 6) ////////////////////////////////////////////////////////////////////////////////
*** 2432,2442 **** bool timedwait(unsigned int sec, int nsec); private: sem_t _semaphore; }; - Semaphore::Semaphore() { sem_init(&_semaphore, 0, 0); } Semaphore::~Semaphore() { --- 2434,2443 ----
*** 2454,2465 **** bool Semaphore::trywait() { return sem_trywait(&_semaphore) == 0; } bool Semaphore::timedwait(unsigned int sec, int nsec) { struct timespec ts; ! unpackTime(&ts, false, (sec * NANOSECS_PER_SEC) + nsec); while (1) { int result = sem_timedwait(&_semaphore, &ts); if (result == 0) { return true; --- 2455,2480 ---- bool Semaphore::trywait() { return sem_trywait(&_semaphore) == 0; } bool Semaphore::timedwait(unsigned int sec, int nsec) { + struct timespec ts; ! // Semaphore's are always associated with CLOCK_REALTIME ! os::Linux::clock_gettime(CLOCK_REALTIME, &ts); ! // see unpackTime for discussion on overflow checking ! if (sec >= MAX_SECS) { ! ts.tv_sec += MAX_SECS; ! ts.tv_nsec = 0; ! } else { ! ts.tv_sec += sec; ! ts.tv_nsec += nsec; ! if (ts.tv_nsec >= NANOSECS_PER_SEC) { ! ts.tv_nsec -= NANOSECS_PER_SEC; ! ++ts.tv_sec; // note: this must be <= max_secs ! } ! } while (1) { int result = sem_timedwait(&_semaphore, &ts); if (result == 0) { return true;
*** 5654,5664 **** * on the condvar. Contention seen when trying to park implies that someone * is unparking you, so don't wait. And spurious returns are fine, so there * is no need to track notifications. */ - #define MAX_SECS 100000000 /* * This code is common to linux and solaris and will be moved to a * common place in dolphin. * * The passed in time value is either a relative time in nanoseconds --- 5669,5678 ----