OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 struct rusage usage; | 306 struct rusage usage; |
307 | 307 |
308 if (getrusage(RUSAGE_SELF, &usage) < 0) return -1; | 308 if (getrusage(RUSAGE_SELF, &usage) < 0) return -1; |
309 *secs = usage.ru_utime.tv_sec; | 309 *secs = usage.ru_utime.tv_sec; |
310 *usecs = usage.ru_utime.tv_usec; | 310 *usecs = usage.ru_utime.tv_usec; |
311 return 0; | 311 return 0; |
312 } | 312 } |
313 | 313 |
314 | 314 |
315 double OS::TimeCurrentMillis() { | 315 double OS::TimeCurrentMillis() { |
316 return Time::Now().ToJsTime(); | 316 struct timeval tv; |
| 317 if (gettimeofday(&tv, NULL) < 0) return 0.0; |
| 318 return (static_cast<double>(tv.tv_sec) * 1000) + |
| 319 (static_cast<double>(tv.tv_usec) / 1000); |
317 } | 320 } |
318 | 321 |
319 | 322 |
| 323 int64_t OS::Ticks() { |
| 324 // gettimeofday has microsecond resolution. |
| 325 struct timeval tv; |
| 326 if (gettimeofday(&tv, NULL) < 0) |
| 327 return 0; |
| 328 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; |
| 329 } |
| 330 |
| 331 |
320 double OS::DaylightSavingsOffset(double time) { | 332 double OS::DaylightSavingsOffset(double time) { |
321 if (std::isnan(time)) return nan_value(); | 333 if (std::isnan(time)) return nan_value(); |
322 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); | 334 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); |
323 struct tm* t = localtime(&tv); | 335 struct tm* t = localtime(&tv); |
324 if (NULL == t) return nan_value(); | 336 if (NULL == t) return nan_value(); |
325 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0; | 337 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0; |
326 } | 338 } |
327 | 339 |
328 | 340 |
329 int OS::GetLastError() { | 341 int OS::GetLastError() { |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 return ntohl(value); | 985 return ntohl(value); |
974 } | 986 } |
975 | 987 |
976 | 988 |
977 Socket* OS::CreateSocket() { | 989 Socket* OS::CreateSocket() { |
978 return new POSIXSocket(); | 990 return new POSIXSocket(); |
979 } | 991 } |
980 | 992 |
981 | 993 |
982 } } // namespace v8::internal | 994 } } // namespace v8::internal |
OLD | NEW |