Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(914)

Side by Side Diff: src/platform-linux.cc

Issue 69024: - Fix delta time calculation in LinuxSemaphore::Wait. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-freebsd.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 while (true) { 502 while (true) {
503 int result = sem_wait(&sem_); 503 int result = sem_wait(&sem_);
504 if (result == 0) return; // Successfully got semaphore. 504 if (result == 0) return; // Successfully got semaphore.
505 CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup. 505 CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup.
506 } 506 }
507 } 507 }
508 508
509 509
510 bool LinuxSemaphore::Wait(int timeout) { 510 bool LinuxSemaphore::Wait(int timeout) {
511 const long kOneSecondMicros = 1000000; // NOLINT 511 const long kOneSecondMicros = 1000000; // NOLINT
512 const long kOneSecondNanos = 1000000000; // NOLINT 512
513
514 // Split timeout into second and nanosecond parts. 513 // Split timeout into second and nanosecond parts.
515 long nanos = (timeout % kOneSecondMicros) * 1000; // NOLINT 514 struct timeval delta;
516 time_t secs = timeout / kOneSecondMicros; 515 delta.tv_usec = timeout % kOneSecondMicros;
517 516 delta.tv_sec = timeout / kOneSecondMicros;
518 // Get the current realtime clock. 517
519 struct timespec ts; 518 struct timeval current_time;
520 if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { 519 // Get the current time.
520 if (gettimeofday(&current_time, NULL) == -1) {
521 return false; 521 return false;
522 } 522 }
523 523
524 // Calculate real time for end of timeout. 524 // Calculate time for end of timeout.
525 ts.tv_nsec += nanos; 525 struct timeval end_time;
526 if (ts.tv_nsec >= kOneSecondNanos) { 526 timeradd(&current_time, &delta, &end_time);
527 ts.tv_nsec -= kOneSecondNanos; 527
528 ts.tv_nsec++; 528 struct timespec ts;
529 } 529 TIMEVAL_TO_TIMESPEC(&end_time, &ts);
530 ts.tv_sec += secs;
531
532 // Wait for semaphore signalled or timeout. 530 // Wait for semaphore signalled or timeout.
533 while (true) { 531 while (true) {
534 int result = sem_timedwait(&sem_, &ts); 532 int result = sem_timedwait(&sem_, &ts);
535 if (result == 0) return true; // Successfully got semaphore. 533 if (result == 0) return true; // Successfully got semaphore.
536 if (result > 0) { 534 if (result > 0) {
537 // For glibc prior to 2.3.4 sem_timedwait returns the error instead of -1. 535 // For glibc prior to 2.3.4 sem_timedwait returns the error instead of -1.
538 errno = result; 536 errno = result;
539 result = -1; 537 result = -1;
540 } 538 }
541 if (result == -1 && errno == ETIMEDOUT) return false; // Timeout. 539 if (result == -1 && errno == ETIMEDOUT) return false; // Timeout.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 } 667 }
670 668
671 // This sampler is no longer the active sampler. 669 // This sampler is no longer the active sampler.
672 active_sampler_ = NULL; 670 active_sampler_ = NULL;
673 active_ = false; 671 active_ = false;
674 } 672 }
675 673
676 #endif // ENABLE_LOGGING_AND_PROFILING 674 #endif // ENABLE_LOGGING_AND_PROFILING
677 675
678 } } // namespace v8::internal 676 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-freebsd.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698