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

Side by Side Diff: src/platform-freebsd.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 | « SConstruct ('k') | src/platform-linux.cc » ('j') | 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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 while (true) { 496 while (true) {
497 int result = sem_wait(&sem_); 497 int result = sem_wait(&sem_);
498 if (result == 0) return; // Successfully got semaphore. 498 if (result == 0) return; // Successfully got semaphore.
499 CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup. 499 CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup.
500 } 500 }
501 } 501 }
502 502
503 503
504 bool FreeBSDSemaphore::Wait(int timeout) { 504 bool FreeBSDSemaphore::Wait(int timeout) {
505 const long kOneSecondMicros = 1000000; // NOLINT 505 const long kOneSecondMicros = 1000000; // NOLINT
506 const long kOneSecondNanos = 1000000000; // NOLINT 506
507
508 // Split timeout into second and nanosecond parts. 507 // Split timeout into second and nanosecond parts.
509 long nanos = (timeout % kOneSecondMicros) * 1000; // NOLINT 508 struct timeval delta;
510 time_t secs = timeout / kOneSecondMicros; 509 delta.tv_usec = timeout % kOneSecondMicros;
511 510 delta.tv_sec = timeout / kOneSecondMicros;
512 // Get the current real time clock. 511
513 struct timespec ts; 512 struct timeval current_time;
514 if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { 513 // Get the current time.
514 if (gettimeofday(&current_time, NULL) == -1) {
515 return false; 515 return false;
516 } 516 }
517 517
518 // Calculate realtime for end of timeout. 518 // Calculate time for end of timeout.
519 ts.tv_nsec += nanos; 519 struct timeval end_time;
520 if (ts.tv_nsec >= kOneSecondNanos) { 520 timeradd(&current_time, &delta, &end_time);
521 ts.tv_nsec -= kOneSecondNanos; 521
522 ts.tv_nsec++; 522 struct timespec ts;
523 } 523 TIMEVAL_TO_TIMESPEC(&end_time, &ts);
524 ts.tv_sec += secs;
525
526 // Wait for semaphore signalled or timeout.
527 while (true) { 524 while (true) {
528 int result = sem_timedwait(&sem_, &ts); 525 int result = sem_timedwait(&sem_, &ts);
529 if (result == 0) return true; // Successfully got semaphore. 526 if (result == 0) return true; // Successfully got semaphore.
530 if (result == -1 && errno == ETIMEDOUT) return false; // Timeout. 527 if (result == -1 && errno == ETIMEDOUT) return false; // Timeout.
531 CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup. 528 CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup.
532 } 529 }
533 } 530 }
534 531
535 532
536 Semaphore* OS::CreateSemaphore(int count) { 533 Semaphore* OS::CreateSemaphore(int count) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 } 628 }
632 629
633 // This sampler is no longer the active sampler. 630 // This sampler is no longer the active sampler.
634 active_sampler_ = NULL; 631 active_sampler_ = NULL;
635 active_ = false; 632 active_ = false;
636 } 633 }
637 634
638 #endif // ENABLE_LOGGING_AND_PROFILING 635 #endif // ENABLE_LOGGING_AND_PROFILING
639 636
640 } } // namespace v8::internal 637 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « SConstruct ('k') | src/platform-linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698