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

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

Issue 53045: Move time related functions to POSIX platform file (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 9 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-linux.cc ('k') | src/platform-posix.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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Seed the random number generator. 79 // Seed the random number generator.
80 // Convert the current time to a 64-bit integer first, before converting it 80 // Convert the current time to a 64-bit integer first, before converting it
81 // to an unsigned. Going directly will cause an overflow and the seed to be 81 // to an unsigned. Going directly will cause an overflow and the seed to be
82 // set to all ones. The seed will be identical for different instances that 82 // set to all ones. The seed will be identical for different instances that
83 // call this setup code within the same millisecond. 83 // call this setup code within the same millisecond.
84 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); 84 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
85 srandom(static_cast<unsigned int>(seed)); 85 srandom(static_cast<unsigned int>(seed));
86 } 86 }
87 87
88 88
89 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) {
90 struct rusage usage;
91
92 if (getrusage(RUSAGE_SELF, &usage) < 0) return -1;
93 *secs = usage.ru_utime.tv_sec;
94 *usecs = usage.ru_utime.tv_usec;
95 return 0;
96 }
97
98
99 double OS::TimeCurrentMillis() {
100 struct timeval tv;
101 if (gettimeofday(&tv, NULL) < 0) return 0.0;
102 return (static_cast<double>(tv.tv_sec) * 1000) +
103 (static_cast<double>(tv.tv_usec) / 1000);
104 }
105
106
107 int64_t OS::Ticks() {
108 // Mac OS's gettimeofday has microsecond resolution.
109 struct timeval tv;
110 if (gettimeofday(&tv, NULL) < 0)
111 return 0;
112 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec;
113 }
114
115
116 char* OS::LocalTimezone(double time) {
117 time_t tv = static_cast<time_t>(floor(time/msPerSecond));
118 struct tm* t = localtime(&tv);
119 return const_cast<char*>(t->tm_zone);
120 }
121
122
123 double OS::DaylightSavingsOffset(double time) {
124 time_t tv = static_cast<time_t>(floor(time/msPerSecond));
125 struct tm* t = localtime(&tv);
126 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0;
127 }
128
129
130 double OS::LocalTimeOffset() {
131 time_t tv = time(NULL);
132 struct tm* t = localtime(&tv);
133 // tm_gmtoff includes any daylight savings offset, so subtract it.
134 return static_cast<double>(t->tm_gmtoff * msPerSecond -
135 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
136 }
137
138
139 FILE* OS::FOpen(const char* path, const char* mode) { 89 FILE* OS::FOpen(const char* path, const char* mode) {
140 return fopen(path, mode); 90 return fopen(path, mode);
141 } 91 }
142 92
143 93
144 void OS::Print(const char* format, ...) { 94 void OS::Print(const char* format, ...) {
145 va_list args; 95 va_list args;
146 va_start(args, format); 96 va_start(args, format);
147 VPrint(format, args); 97 VPrint(format, args);
148 va_end(args); 98 va_end(args);
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 } 605 }
656 606
657 // This sampler is no longer the active sampler. 607 // This sampler is no longer the active sampler.
658 active_sampler_ = NULL; 608 active_sampler_ = NULL;
659 active_ = false; 609 active_ = false;
660 } 610 }
661 611
662 #endif // ENABLE_LOGGING_AND_PROFILING 612 #endif // ENABLE_LOGGING_AND_PROFILING
663 613
664 } } // namespace v8::internal 614 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698