src/os/linux/vm/os_linux.cpp
Print this page
rev 6079 : 8037340: Linux semaphores to use CLOCK_REALTIME
Reviewed-by:
@@ -107,10 +107,12 @@
#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,11 +2434,10 @@
bool timedwait(unsigned int sec, int nsec);
private:
sem_t _semaphore;
};
-
Semaphore::Semaphore() {
sem_init(&_semaphore, 0, 0);
}
Semaphore::~Semaphore() {
@@ -2454,12 +2455,26 @@
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);
+ // 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,11 +5669,10 @@
* 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