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

Side by Side Diff: src/platform/time.cc

Issue 70133003: CLOCK_REALTIME is 0 on Linux, use -1 for invalid clock id. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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 | « no previous file | 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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // cleanup the tools/gyp/v8.gyp file. 288 // cleanup the tools/gyp/v8.gyp file.
289 struct timeval tv; 289 struct timeval tv;
290 int result = gettimeofday(&tv, NULL); 290 int result = gettimeofday(&tv, NULL);
291 ASSERT_EQ(0, result); 291 ASSERT_EQ(0, result);
292 USE(result); 292 USE(result);
293 return FromTimeval(tv); 293 return FromTimeval(tv);
294 #elif defined(CLOCK_REALTIME_COARSE) 294 #elif defined(CLOCK_REALTIME_COARSE)
295 struct timespec ts; 295 struct timespec ts;
296 // Use CLOCK_REALTIME_COARSE if it's available and has a precision of 1ms 296 // Use CLOCK_REALTIME_COARSE if it's available and has a precision of 1ms
297 // or higher. It's serviced from the vDSO with no system call overhead. 297 // or higher. It's serviced from the vDSO with no system call overhead.
298 static clock_t clock_id = static_cast<clock_t>(0); 298 static clock_t clock_id = static_cast<clock_t>(-1);
299 if (!clock_id) { 299 STATIC_ASSERT(CLOCK_REALTIME != static_cast<clock_t>(-1));
300 STATIC_ASSERT(CLOCK_REALTIME_COARSE != static_cast<clock_t>(-1));
301 if (clock_id == static_cast<clock_t>(-1)) {
300 if (clock_getres(CLOCK_REALTIME_COARSE, &ts) == 0 302 if (clock_getres(CLOCK_REALTIME_COARSE, &ts) == 0
301 && ts.tv_nsec <= kNanosecondsPerMillisecond) 303 && ts.tv_nsec <= kNanosecondsPerMillisecond)
302 clock_id = CLOCK_REALTIME_COARSE; 304 clock_id = CLOCK_REALTIME_COARSE;
303 else 305 else
304 clock_id = CLOCK_REALTIME; 306 clock_id = CLOCK_REALTIME;
305 } 307 }
306 int result = clock_gettime(clock_id, &ts); 308 int result = clock_gettime(clock_id, &ts);
307 ASSERT_EQ(0, result); 309 ASSERT_EQ(0, result);
308 USE(result); 310 USE(result);
309 return FromTimespec(ts); 311 return FromTimespec(ts);
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 struct timeval tv; 606 struct timeval tv;
605 int result = gettimeofday(&tv, NULL); 607 int result = gettimeofday(&tv, NULL);
606 ASSERT_EQ(0, result); 608 ASSERT_EQ(0, result);
607 USE(result); 609 USE(result);
608 ticks = (tv.tv_sec * Time::kMicrosecondsPerSecond + tv.tv_usec); 610 ticks = (tv.tv_sec * Time::kMicrosecondsPerSecond + tv.tv_usec);
609 #elif V8_OS_POSIX 611 #elif V8_OS_POSIX
610 struct timespec ts; 612 struct timespec ts;
611 #if defined(CLOCK_MONOTONIC_COARSE) 613 #if defined(CLOCK_MONOTONIC_COARSE)
612 // Use CLOCK_MONOTONIC_COARSE if it's available and has a precision of 1ms 614 // Use CLOCK_MONOTONIC_COARSE if it's available and has a precision of 1ms
613 // or higher. It's serviced from the vDSO with no system call overhead. 615 // or higher. It's serviced from the vDSO with no system call overhead.
614 static clock_t clock_id = static_cast<clock_t>(0); 616 static clock_t clock_id = static_cast<clock_t>(-1);
615 if (!clock_id) { 617 STATIC_ASSERT(CLOCK_MONOTONIC != static_cast<clock_t>(-1));
618 STATIC_ASSERT(CLOCK_MONOTONIC_COARSE != static_cast<clock_t>(-1));
619 if (clock_id == static_cast<clock_t>(-1)) {
616 if (clock_getres(CLOCK_MONOTONIC_COARSE, &ts) == 0 620 if (clock_getres(CLOCK_MONOTONIC_COARSE, &ts) == 0
617 && ts.tv_nsec <= Time::kNanosecondsPerMillisecond) 621 && ts.tv_nsec <= Time::kNanosecondsPerMillisecond)
618 clock_id = CLOCK_MONOTONIC_COARSE; 622 clock_id = CLOCK_MONOTONIC_COARSE;
619 else 623 else
620 clock_id = CLOCK_MONOTONIC; 624 clock_id = CLOCK_MONOTONIC;
621 } 625 }
622 #else 626 #else
623 static const clock_t clock_id = CLOCK_MONOTONIC; 627 static const clock_t clock_id = CLOCK_MONOTONIC;
624 #endif // defined(CLOCK_MONOTONIC_COARSE) 628 #endif // defined(CLOCK_MONOTONIC_COARSE)
625 int result = clock_gettime(clock_id, &ts); 629 int result = clock_gettime(clock_id, &ts);
626 ASSERT_EQ(0, result); 630 ASSERT_EQ(0, result);
627 USE(result); 631 USE(result);
628 ticks = (ts.tv_sec * Time::kMicrosecondsPerSecond + 632 ticks = (ts.tv_sec * Time::kMicrosecondsPerSecond +
629 ts.tv_nsec / Time::kNanosecondsPerMicrosecond); 633 ts.tv_nsec / Time::kNanosecondsPerMicrosecond);
630 #endif // V8_OS_MACOSX 634 #endif // V8_OS_MACOSX
631 // Make sure we never return 0 here. 635 // Make sure we never return 0 here.
632 return TimeTicks(ticks + 1); 636 return TimeTicks(ticks + 1);
633 } 637 }
634 638
635 639
636 // static 640 // static
637 bool TimeTicks::IsHighResolutionClockWorking() { 641 bool TimeTicks::IsHighResolutionClockWorking() {
638 return true; 642 return true;
639 } 643 }
640 644
641 #endif // V8_OS_WIN 645 #endif // V8_OS_WIN
642 646
643 } } // namespace v8::internal 647 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698