OLD | NEW |
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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 // timestamp taking into account daylight saving. | 486 // timestamp taking into account daylight saving. |
487 char* Time::LocalTimezone() { | 487 char* Time::LocalTimezone() { |
488 // Return the standard or DST time zone name based on whether daylight | 488 // Return the standard or DST time zone name based on whether daylight |
489 // saving is in effect at the given time. | 489 // saving is in effect at the given time. |
490 return InDST() ? dst_tz_name_ : std_tz_name_; | 490 return InDST() ? dst_tz_name_ : std_tz_name_; |
491 } | 491 } |
492 | 492 |
493 | 493 |
494 void OS::Setup() { | 494 void OS::Setup() { |
495 // Seed the random number generator. | 495 // Seed the random number generator. |
496 srand(static_cast<unsigned int>(TimeCurrentMillis())); | 496 // Convert the current time to a 64-bit integer first, before converting it |
| 497 // to an unsigned. Going directly can cause an overflow and the seed to be |
| 498 // set to all ones. The seed will be identical for different instances that |
| 499 // call this setup code within the same millisecond. |
| 500 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); |
| 501 srand(static_cast<unsigned int>(seed)); |
497 } | 502 } |
498 | 503 |
499 | 504 |
500 // Returns the accumulated user time for thread. | 505 // Returns the accumulated user time for thread. |
501 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { | 506 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { |
502 FILETIME dummy; | 507 FILETIME dummy; |
503 uint64_t usertime; | 508 uint64_t usertime; |
504 | 509 |
505 // Get the amount of time that the thread has executed in user mode. | 510 // Get the amount of time that the thread has executed in user mode. |
506 if (!GetThreadTimes(GetCurrentThread(), &dummy, &dummy, &dummy, | 511 if (!GetThreadTimes(GetCurrentThread(), &dummy, &dummy, &dummy, |
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 | 1530 |
1526 // Release the thread handles | 1531 // Release the thread handles |
1527 CloseHandle(data_->sampler_thread_); | 1532 CloseHandle(data_->sampler_thread_); |
1528 CloseHandle(data_->profiled_thread_); | 1533 CloseHandle(data_->profiled_thread_); |
1529 } | 1534 } |
1530 | 1535 |
1531 | 1536 |
1532 #endif // ENABLE_LOGGING_AND_PROFILING | 1537 #endif // ENABLE_LOGGING_AND_PROFILING |
1533 | 1538 |
1534 } } // namespace v8::internal | 1539 } } // namespace v8::internal |
OLD | NEW |