Author: [email protected]
Date: Thu Apr 16 17:56:52 2009
New Revision: 1732

Modified:
    branches/bleeding_edge/SConstruct
    branches/bleeding_edge/src/platform-freebsd.cc
    branches/bleeding_edge/src/platform-linux.cc

Log:
- Fix delta time calculation in LinuxSemaphore::Wait.

Review URL: http://codereview.chromium.org/69024

Modified: branches/bleeding_edge/SConstruct
==============================================================================
--- branches/bleeding_edge/SConstruct   (original)
+++ branches/bleeding_edge/SConstruct   Thu Apr 16 17:56:52 2009
@@ -108,7 +108,7 @@
      'os:linux': {
        'CCFLAGS':      ['-ansi'],
        'library:shared': {
-        'LIBS': ['pthread', 'rt']
+        'LIBS': ['pthread']
        }
      },
      'os:macos': {
@@ -224,7 +224,7 @@
  MKSNAPSHOT_EXTRA_FLAGS = {
    'gcc': {
      'os:linux': {
-      'LIBS': ['pthread', 'rt'],
+      'LIBS': ['pthread'],
      },
      'os:macos': {
        'LIBS': ['pthread'],
@@ -269,7 +269,7 @@
        'LIBPATH': [abspath('.')]
      },
      'os:linux': {
-      'LIBS':         ['pthread', 'rt'],
+      'LIBS':         ['pthread'],
      },
      'os:macos': {
        'LIBS':         ['pthread'],
@@ -308,7 +308,7 @@
        'CCFLAGS': ['-fno-rtti', '-fno-exceptions']
      },
      'os:linux': {
-      'LIBS':         ['pthread', 'rt'],
+      'LIBS':         ['pthread'],
      },
      'os:macos': {
        'LIBS':         ['pthread'],
@@ -388,7 +388,7 @@
        'LIBS': ['readline']
      },
      'os:linux': {
-      'LIBS': ['pthread', 'rt'],
+      'LIBS': ['pthread'],
      },
      'os:macos': {
        'LIBS': ['pthread'],

Modified: branches/bleeding_edge/src/platform-freebsd.cc
==============================================================================
--- branches/bleeding_edge/src/platform-freebsd.cc      (original)
+++ branches/bleeding_edge/src/platform-freebsd.cc      Thu Apr 16 17:56:52 2009
@@ -503,27 +503,24 @@

  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(&current_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(&current_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.

Modified: branches/bleeding_edge/src/platform-linux.cc
==============================================================================
--- branches/bleeding_edge/src/platform-linux.cc        (original)
+++ branches/bleeding_edge/src/platform-linux.cc        Thu Apr 16 17:56:52 2009
@@ -509,26 +509,24 @@

  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(&current_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(&current_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);

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to