Chromium Code Reviews| 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 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 | 584 |
| 585 | 585 |
| 586 // Returns current time as the number of milliseconds since | 586 // Returns current time as the number of milliseconds since |
| 587 // 00:00:00 UTC, January 1, 1970. | 587 // 00:00:00 UTC, January 1, 1970. |
| 588 double OS::TimeCurrentMillis() { | 588 double OS::TimeCurrentMillis() { |
| 589 Time t; | 589 Time t; |
| 590 t.SetToCurrentTime(); | 590 t.SetToCurrentTime(); |
| 591 return t.ToJSTime(); | 591 return t.ToJSTime(); |
| 592 } | 592 } |
| 593 | 593 |
| 594 // Returns the tickcounter based on timeGetTime. | 594 |
| 595 static LARGE_INTEGER* frequency = NULL; | |
|
caseq
2012/08/27 09:09:58
Does this have to be dynamically allocated?
| |
| 596 | |
| 597 | |
| 598 // Returns the tickcounter based on QueryPerformanceCounter or timeGetTime. | |
| 595 int64_t OS::Ticks() { | 599 int64_t OS::Ticks() { |
| 596 return timeGetTime() * 1000; // Convert to microseconds. | 600 static LARGE_INTEGER tick; |
| 601 if (frequency != NULL && QueryPerformanceCounter(&tick)) { | |
| 602 return static_cast<int64_t>(tick.QuadPart * 1000000.0 / frequency->QuadPart) ; | |
| 603 } else { | |
|
caseq
2012/08/27 09:09:58
I'd drop the parenthesis and "else".
| |
| 604 return timeGetTime() * 1000; // Convert to microseconds. | |
| 605 } | |
| 597 } | 606 } |
| 598 | 607 |
| 599 | 608 |
| 600 // Returns a string identifying the current timezone taking into | 609 // Returns a string identifying the current timezone taking into |
| 601 // account daylight saving. | 610 // account daylight saving. |
| 602 const char* OS::LocalTimezone(double time) { | 611 const char* OS::LocalTimezone(double time) { |
| 603 return Time(time).LocalTimezone(); | 612 return Time(time).LocalTimezone(); |
| 604 } | 613 } |
| 605 | 614 |
| 606 | 615 |
| (...skipping 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2080 | 2089 |
| 2081 | 2090 |
| 2082 void OS::SetUp() { | 2091 void OS::SetUp() { |
| 2083 // Seed the random number generator. | 2092 // Seed the random number generator. |
| 2084 // Convert the current time to a 64-bit integer first, before converting it | 2093 // Convert the current time to a 64-bit integer first, before converting it |
| 2085 // to an unsigned. Going directly can cause an overflow and the seed to be | 2094 // to an unsigned. Going directly can cause an overflow and the seed to be |
| 2086 // set to all ones. The seed will be identical for different instances that | 2095 // set to all ones. The seed will be identical for different instances that |
| 2087 // call this setup code within the same millisecond. | 2096 // call this setup code within the same millisecond. |
| 2088 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); | 2097 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); |
| 2089 srand(static_cast<unsigned int>(seed)); | 2098 srand(static_cast<unsigned int>(seed)); |
| 2099 // Get the number of ticks per second that is used in OS::Ticks() | |
| 2100 frequency = new LARGE_INTEGER(); | |
| 2101 if (!QueryPerformanceFrequency(frequency)) { | |
| 2102 delete frequency; | |
| 2103 frequency = NULL; | |
| 2104 } | |
| 2090 limit_mutex = CreateMutex(); | 2105 limit_mutex = CreateMutex(); |
| 2091 SamplerThread::SetUp(); | 2106 SamplerThread::SetUp(); |
| 2092 } | 2107 } |
| 2093 | 2108 |
| 2094 | 2109 |
| 2095 void OS::TearDown() { | 2110 void OS::TearDown() { |
| 2111 delete frequency; | |
| 2112 frequency = NULL; | |
| 2096 SamplerThread::TearDown(); | 2113 SamplerThread::TearDown(); |
| 2097 delete limit_mutex; | 2114 delete limit_mutex; |
| 2098 } | 2115 } |
| 2099 | 2116 |
| 2100 | 2117 |
| 2101 Sampler::Sampler(Isolate* isolate, int interval) | 2118 Sampler::Sampler(Isolate* isolate, int interval) |
| 2102 : isolate_(isolate), | 2119 : isolate_(isolate), |
| 2103 interval_(interval), | 2120 interval_(interval), |
| 2104 profiling_(false), | 2121 profiling_(false), |
| 2105 active_(false), | 2122 active_(false), |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2122 | 2139 |
| 2123 | 2140 |
| 2124 void Sampler::Stop() { | 2141 void Sampler::Stop() { |
| 2125 ASSERT(IsActive()); | 2142 ASSERT(IsActive()); |
| 2126 SamplerThread::RemoveActiveSampler(this); | 2143 SamplerThread::RemoveActiveSampler(this); |
| 2127 SetActive(false); | 2144 SetActive(false); |
| 2128 } | 2145 } |
| 2129 | 2146 |
| 2130 | 2147 |
| 2131 } } // namespace v8::internal | 2148 } } // namespace v8::internal |
| OLD | NEW |