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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 struct rusage usage; | 311 struct rusage usage; |
312 | 312 |
313 if (getrusage(RUSAGE_SELF, &usage) < 0) return -1; | 313 if (getrusage(RUSAGE_SELF, &usage) < 0) return -1; |
314 *secs = usage.ru_utime.tv_sec; | 314 *secs = usage.ru_utime.tv_sec; |
315 *usecs = usage.ru_utime.tv_usec; | 315 *usecs = usage.ru_utime.tv_usec; |
316 return 0; | 316 return 0; |
317 } | 317 } |
318 | 318 |
319 | 319 |
320 double OS::TimeCurrentMillis() { | 320 double OS::TimeCurrentMillis() { |
321 return Time::Now().ToJsTime(); | 321 struct timeval tv; |
| 322 if (gettimeofday(&tv, NULL) < 0) return 0.0; |
| 323 return (static_cast<double>(tv.tv_sec) * 1000) + |
| 324 (static_cast<double>(tv.tv_usec) / 1000); |
322 } | 325 } |
323 | 326 |
324 | 327 |
| 328 int64_t OS::Ticks() { |
| 329 // gettimeofday has microsecond resolution. |
| 330 struct timeval tv; |
| 331 if (gettimeofday(&tv, NULL) < 0) |
| 332 return 0; |
| 333 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; |
| 334 } |
| 335 |
| 336 |
325 double OS::DaylightSavingsOffset(double time) { | 337 double OS::DaylightSavingsOffset(double time) { |
326 if (std::isnan(time)) return nan_value(); | 338 if (std::isnan(time)) return nan_value(); |
327 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); | 339 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); |
328 struct tm* t = localtime(&tv); | 340 struct tm* t = localtime(&tv); |
329 if (NULL == t) return nan_value(); | 341 if (NULL == t) return nan_value(); |
330 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0; | 342 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0; |
331 } | 343 } |
332 | 344 |
333 | 345 |
334 int OS::GetLastError() { | 346 int OS::GetLastError() { |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 return ntohl(value); | 990 return ntohl(value); |
979 } | 991 } |
980 | 992 |
981 | 993 |
982 Socket* OS::CreateSocket() { | 994 Socket* OS::CreateSocket() { |
983 return new POSIXSocket(); | 995 return new POSIXSocket(); |
984 } | 996 } |
985 | 997 |
986 | 998 |
987 } } // namespace v8::internal | 999 } } // namespace v8::internal |
OLD | NEW |