| 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 public: | 374 public: |
| 375 PlatformData() : thread_(kNoThread) {} | 375 PlatformData() : thread_(kNoThread) {} |
| 376 pthread_t thread_; // Thread handle for pthread. | 376 pthread_t thread_; // Thread handle for pthread. |
| 377 }; | 377 }; |
| 378 | 378 |
| 379 | 379 |
| 380 | 380 |
| 381 | 381 |
| 382 Thread::Thread(const Options& options) | 382 Thread::Thread(const Options& options) |
| 383 : data_(new PlatformData()), | 383 : data_(new PlatformData()), |
| 384 stack_size_(options.stack_size()) { | 384 stack_size_(options.stack_size()), |
| 385 start_semaphore_(NULL) { |
| 385 set_name(options.name()); | 386 set_name(options.name()); |
| 386 } | 387 } |
| 387 | 388 |
| 388 | 389 |
| 389 Thread::~Thread() { | 390 Thread::~Thread() { |
| 390 delete data_; | 391 delete data_; |
| 391 } | 392 } |
| 392 | 393 |
| 393 | 394 |
| 394 static void* ThreadEntry(void* arg) { | 395 static void* ThreadEntry(void* arg) { |
| 395 Thread* thread = reinterpret_cast<Thread*>(arg); | 396 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 396 // This is also initialized by the first argument to pthread_create() but we | 397 // This is also initialized by the first argument to pthread_create() but we |
| 397 // don't know which thread will run first (the original thread or the new | 398 // don't know which thread will run first (the original thread or the new |
| 398 // one) so we initialize it here too. | 399 // one) so we initialize it here too. |
| 399 thread->data()->thread_ = pthread_self(); | 400 thread->data()->thread_ = pthread_self(); |
| 400 ASSERT(thread->data()->thread_ != kNoThread); | 401 ASSERT(thread->data()->thread_ != kNoThread); |
| 401 thread->Run(); | 402 thread->NotifyStartedAndRun(); |
| 402 return NULL; | 403 return NULL; |
| 403 } | 404 } |
| 404 | 405 |
| 405 | 406 |
| 406 void Thread::set_name(const char* name) { | 407 void Thread::set_name(const char* name) { |
| 407 strncpy(name_, name, sizeof(name_)); | 408 strncpy(name_, name, sizeof(name_)); |
| 408 name_[sizeof(name_) - 1] = '\0'; | 409 name_[sizeof(name_) - 1] = '\0'; |
| 409 } | 410 } |
| 410 | 411 |
| 411 | 412 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 interval_(interval) {} | 633 interval_(interval) {} |
| 633 | 634 |
| 634 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } | 635 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } |
| 635 static void TearDown() { delete mutex_; } | 636 static void TearDown() { delete mutex_; } |
| 636 | 637 |
| 637 static void AddActiveSampler(Sampler* sampler) { | 638 static void AddActiveSampler(Sampler* sampler) { |
| 638 ScopedLock lock(mutex_); | 639 ScopedLock lock(mutex_); |
| 639 SamplerRegistry::AddActiveSampler(sampler); | 640 SamplerRegistry::AddActiveSampler(sampler); |
| 640 if (instance_ == NULL) { | 641 if (instance_ == NULL) { |
| 641 instance_ = new SamplerThread(sampler->interval()); | 642 instance_ = new SamplerThread(sampler->interval()); |
| 642 instance_->Start(); | 643 instance_->StartSynchronously(); |
| 643 } else { | 644 } else { |
| 644 ASSERT(instance_->interval_ == sampler->interval()); | 645 ASSERT(instance_->interval_ == sampler->interval()); |
| 645 } | 646 } |
| 646 } | 647 } |
| 647 | 648 |
| 648 static void RemoveActiveSampler(Sampler* sampler) { | 649 static void RemoveActiveSampler(Sampler* sampler) { |
| 649 ScopedLock lock(mutex_); | 650 ScopedLock lock(mutex_); |
| 650 SamplerRegistry::RemoveActiveSampler(sampler); | 651 SamplerRegistry::RemoveActiveSampler(sampler); |
| 651 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 652 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
| 652 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); | 653 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 | 772 |
| 772 | 773 |
| 773 void Sampler::Stop() { | 774 void Sampler::Stop() { |
| 774 ASSERT(IsActive()); | 775 ASSERT(IsActive()); |
| 775 SamplerThread::RemoveActiveSampler(this); | 776 SamplerThread::RemoveActiveSampler(this); |
| 776 SetActive(false); | 777 SetActive(false); |
| 777 } | 778 } |
| 778 | 779 |
| 779 | 780 |
| 780 } } // namespace v8::internal | 781 } } // namespace v8::internal |
| OLD | NEW |