From: iposva@chromium.org Date: Fri, 17 Apr 2009 00:56:52 +0000 (+0000) Subject: - Fix delta time calculation in LinuxSemaphore::Wait. X-Git-Tag: upstream/4.7.83~24297 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7dece760ad3df22839dbb4534db7cb306938461f;p=platform%2Fupstream%2Fv8.git - Fix delta time calculation in LinuxSemaphore::Wait. Review URL: http://codereview.chromium.org/69024 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1732 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/SConstruct b/SConstruct index f13c058..1024a5b 100644 --- a/SConstruct +++ b/SConstruct @@ -108,7 +108,7 @@ LIBRARY_FLAGS = { 'os:linux': { 'CCFLAGS': ['-ansi'], 'library:shared': { - 'LIBS': ['pthread', 'rt'] + 'LIBS': ['pthread'] } }, 'os:macos': { @@ -224,7 +224,7 @@ V8_EXTRA_FLAGS = { MKSNAPSHOT_EXTRA_FLAGS = { 'gcc': { 'os:linux': { - 'LIBS': ['pthread', 'rt'], + 'LIBS': ['pthread'], }, 'os:macos': { 'LIBS': ['pthread'], @@ -269,7 +269,7 @@ CCTEST_EXTRA_FLAGS = { 'LIBPATH': [abspath('.')] }, 'os:linux': { - 'LIBS': ['pthread', 'rt'], + 'LIBS': ['pthread'], }, 'os:macos': { 'LIBS': ['pthread'], @@ -308,7 +308,7 @@ SAMPLE_FLAGS = { 'CCFLAGS': ['-fno-rtti', '-fno-exceptions'] }, 'os:linux': { - 'LIBS': ['pthread', 'rt'], + 'LIBS': ['pthread'], }, 'os:macos': { 'LIBS': ['pthread'], @@ -388,7 +388,7 @@ D8_FLAGS = { 'LIBS': ['readline'] }, 'os:linux': { - 'LIBS': ['pthread', 'rt'], + 'LIBS': ['pthread'], }, 'os:macos': { 'LIBS': ['pthread'], diff --git a/src/platform-freebsd.cc b/src/platform-freebsd.cc index 3d22317..1e71704 100644 --- a/src/platform-freebsd.cc +++ b/src/platform-freebsd.cc @@ -503,27 +503,24 @@ void FreeBSDSemaphore::Wait() { bool FreeBSDSemaphore::Wait(int timeout) { const long kOneSecondMicros = 1000000; // NOLINT - const long kOneSecondNanos = 1000000000; // NOLINT // Split timeout into second and nanosecond parts. - long nanos = (timeout % kOneSecondMicros) * 1000; // NOLINT - time_t secs = timeout / kOneSecondMicros; + struct timeval delta; + delta.tv_usec = timeout % kOneSecondMicros; + delta.tv_sec = timeout / kOneSecondMicros; - // Get the current real time clock. - struct timespec ts; - if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { + struct timeval current_time; + // Get the current time. + if (gettimeofday(¤t_time, NULL) == -1) { return false; } - // Calculate realtime for end of timeout. - ts.tv_nsec += nanos; - if (ts.tv_nsec >= kOneSecondNanos) { - ts.tv_nsec -= kOneSecondNanos; - ts.tv_nsec++; - } - ts.tv_sec += secs; + // Calculate time for end of timeout. + struct timeval end_time; + timeradd(¤t_time, &delta, &end_time); - // Wait for semaphore signalled or timeout. + struct timespec ts; + TIMEVAL_TO_TIMESPEC(&end_time, &ts); while (true) { int result = sem_timedwait(&sem_, &ts); if (result == 0) return true; // Successfully got semaphore. diff --git a/src/platform-linux.cc b/src/platform-linux.cc index 3b5351f..7ad50e6 100644 --- a/src/platform-linux.cc +++ b/src/platform-linux.cc @@ -509,26 +509,24 @@ void LinuxSemaphore::Wait() { bool LinuxSemaphore::Wait(int timeout) { const long kOneSecondMicros = 1000000; // NOLINT - const long kOneSecondNanos = 1000000000; // NOLINT // Split timeout into second and nanosecond parts. - long nanos = (timeout % kOneSecondMicros) * 1000; // NOLINT - time_t secs = timeout / kOneSecondMicros; + struct timeval delta; + delta.tv_usec = timeout % kOneSecondMicros; + delta.tv_sec = timeout / kOneSecondMicros; - // Get the current realtime clock. - struct timespec ts; - if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { + struct timeval current_time; + // Get the current time. + if (gettimeofday(¤t_time, NULL) == -1) { return false; } - // Calculate real time for end of timeout. - ts.tv_nsec += nanos; - if (ts.tv_nsec >= kOneSecondNanos) { - ts.tv_nsec -= kOneSecondNanos; - ts.tv_nsec++; - } - ts.tv_sec += secs; + // Calculate time for end of timeout. + struct timeval end_time; + timeradd(¤t_time, &delta, &end_time); + struct timespec ts; + TIMEVAL_TO_TIMESPEC(&end_time, &ts); // Wait for semaphore signalled or timeout. while (true) { int result = sem_timedwait(&sem_, &ts);