aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormgronlun <none@none>2014-03-20 17:31:54 +0100
committermgronlun <none@none>2014-03-20 17:31:54 +0100
commit4ab1a2d1605bfc3d4539c39f2d00f86b5eb1b2fb (patch)
tree7c1eb513e637f70f9b7b8f12fa4fb057d8448256 /src
parentf4f832fe7c22685a73b704ca0f22b57e3242668e (diff)
8037340: Linux semaphores to use CLOCK_REALTIME
Reviewed-by: dholmes, sla
Diffstat (limited to 'src')
-rw-r--r--src/os/linux/vm/os_linux.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp
index d0751f005..94d7e3ed3 100644
--- a/src/os/linux/vm/os_linux.cpp
+++ b/src/os/linux/vm/os_linux.cpp
@@ -109,6 +109,8 @@
#define MAX_PATH (2 * K)
+#define MAX_SECS 100000000
+
// for timer info max values which include all bits
#define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
@@ -2471,7 +2473,6 @@ class Semaphore : public StackObj {
sem_t _semaphore;
};
-
Semaphore::Semaphore() {
sem_init(&_semaphore, 0, 0);
}
@@ -2493,8 +2494,22 @@ bool Semaphore::trywait() {
}
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);
@@ -5808,7 +5823,6 @@ void os::PlatformEvent::unpark() {
* 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.