| 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 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1598 | 1598 |
| 1599 // Definition of invalid thread handle and id. | 1599 // Definition of invalid thread handle and id. |
| 1600 static const HANDLE kNoThread = INVALID_HANDLE_VALUE; | 1600 static const HANDLE kNoThread = INVALID_HANDLE_VALUE; |
| 1601 | 1601 |
| 1602 // Entry point for threads. The supplied argument is a pointer to the thread | 1602 // Entry point for threads. The supplied argument is a pointer to the thread |
| 1603 // object. The entry function dispatches to the run method in the thread | 1603 // object. The entry function dispatches to the run method in the thread |
| 1604 // object. It is important that this function has __stdcall calling | 1604 // object. It is important that this function has __stdcall calling |
| 1605 // convention. | 1605 // convention. |
| 1606 static unsigned int __stdcall ThreadEntry(void* arg) { | 1606 static unsigned int __stdcall ThreadEntry(void* arg) { |
| 1607 Thread* thread = reinterpret_cast<Thread*>(arg); | 1607 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 1608 thread->Run(); | 1608 thread->NotifyStartedAndRun(); |
| 1609 return 0; | 1609 return 0; |
| 1610 } | 1610 } |
| 1611 | 1611 |
| 1612 | 1612 |
| 1613 class Thread::PlatformData : public Malloced { | 1613 class Thread::PlatformData : public Malloced { |
| 1614 public: | 1614 public: |
| 1615 explicit PlatformData(HANDLE thread) : thread_(thread) {} | 1615 explicit PlatformData(HANDLE thread) : thread_(thread) {} |
| 1616 HANDLE thread_; | 1616 HANDLE thread_; |
| 1617 unsigned thread_id_; | 1617 unsigned thread_id_; |
| 1618 }; | 1618 }; |
| 1619 | 1619 |
| 1620 | 1620 |
| 1621 // Initialize a Win32 thread object. The thread has an invalid thread | 1621 // Initialize a Win32 thread object. The thread has an invalid thread |
| 1622 // handle until it is started. | 1622 // handle until it is started. |
| 1623 | 1623 |
| 1624 Thread::Thread(const Options& options) | 1624 Thread::Thread(const Options& options) |
| 1625 : stack_size_(options.stack_size()) { | 1625 : stack_size_(options.stack_size()), |
| 1626 start_semaphore_(NULL) { |
| 1626 data_ = new PlatformData(kNoThread); | 1627 data_ = new PlatformData(kNoThread); |
| 1627 set_name(options.name()); | 1628 set_name(options.name()); |
| 1628 } | 1629 } |
| 1629 | 1630 |
| 1630 | 1631 |
| 1631 void Thread::set_name(const char* name) { | 1632 void Thread::set_name(const char* name) { |
| 1632 OS::StrNCpy(Vector<char>(name_, sizeof(name_)), name, strlen(name)); | 1633 OS::StrNCpy(Vector<char>(name_, sizeof(name_)), name, strlen(name)); |
| 1633 name_[sizeof(name_) - 1] = '\0'; | 1634 name_[sizeof(name_) - 1] = '\0'; |
| 1634 } | 1635 } |
| 1635 | 1636 |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2009 interval_(interval) {} | 2010 interval_(interval) {} |
| 2010 | 2011 |
| 2011 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } | 2012 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } |
| 2012 static void TearDown() { delete mutex_; } | 2013 static void TearDown() { delete mutex_; } |
| 2013 | 2014 |
| 2014 static void AddActiveSampler(Sampler* sampler) { | 2015 static void AddActiveSampler(Sampler* sampler) { |
| 2015 ScopedLock lock(mutex_); | 2016 ScopedLock lock(mutex_); |
| 2016 SamplerRegistry::AddActiveSampler(sampler); | 2017 SamplerRegistry::AddActiveSampler(sampler); |
| 2017 if (instance_ == NULL) { | 2018 if (instance_ == NULL) { |
| 2018 instance_ = new SamplerThread(sampler->interval()); | 2019 instance_ = new SamplerThread(sampler->interval()); |
| 2019 instance_->Start(); | 2020 instance_->StartSynchronously(); |
| 2020 } else { | 2021 } else { |
| 2021 ASSERT(instance_->interval_ == sampler->interval()); | 2022 ASSERT(instance_->interval_ == sampler->interval()); |
| 2022 } | 2023 } |
| 2023 } | 2024 } |
| 2024 | 2025 |
| 2025 static void RemoveActiveSampler(Sampler* sampler) { | 2026 static void RemoveActiveSampler(Sampler* sampler) { |
| 2026 ScopedLock lock(mutex_); | 2027 ScopedLock lock(mutex_); |
| 2027 SamplerRegistry::RemoveActiveSampler(sampler); | 2028 SamplerRegistry::RemoveActiveSampler(sampler); |
| 2028 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 2029 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
| 2029 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); | 2030 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 | 2149 |
| 2149 | 2150 |
| 2150 void Sampler::Stop() { | 2151 void Sampler::Stop() { |
| 2151 ASSERT(IsActive()); | 2152 ASSERT(IsActive()); |
| 2152 SamplerThread::RemoveActiveSampler(this); | 2153 SamplerThread::RemoveActiveSampler(this); |
| 2153 SetActive(false); | 2154 SetActive(false); |
| 2154 } | 2155 } |
| 2155 | 2156 |
| 2156 | 2157 |
| 2157 } } // namespace v8::internal | 2158 } } // namespace v8::internal |
| OLD | NEW |