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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 class Thread::PlatformData : public Malloced { | 463 class Thread::PlatformData : public Malloced { |
464 public: | 464 public: |
465 PlatformData() : thread_(kNoThread) { } | 465 PlatformData() : thread_(kNoThread) { } |
466 | 466 |
467 pthread_t thread_; // Thread handle for pthread. | 467 pthread_t thread_; // Thread handle for pthread. |
468 }; | 468 }; |
469 | 469 |
470 | 470 |
471 Thread::Thread(const Options& options) | 471 Thread::Thread(const Options& options) |
472 : data_(new PlatformData()), | 472 : data_(new PlatformData()), |
473 stack_size_(options.stack_size()) { | 473 stack_size_(options.stack_size()), |
| 474 start_semaphore_(NULL) { |
474 set_name(options.name()); | 475 set_name(options.name()); |
475 } | 476 } |
476 | 477 |
477 | 478 |
478 Thread::~Thread() { | 479 Thread::~Thread() { |
479 delete data_; | 480 delete data_; |
480 } | 481 } |
481 | 482 |
482 | 483 |
483 static void* ThreadEntry(void* arg) { | 484 static void* ThreadEntry(void* arg) { |
484 Thread* thread = reinterpret_cast<Thread*>(arg); | 485 Thread* thread = reinterpret_cast<Thread*>(arg); |
485 // This is also initialized by the first argument to pthread_create() but we | 486 // This is also initialized by the first argument to pthread_create() but we |
486 // don't know which thread will run first (the original thread or the new | 487 // don't know which thread will run first (the original thread or the new |
487 // one) so we initialize it here too. | 488 // one) so we initialize it here too. |
488 thread->data()->thread_ = pthread_self(); | 489 thread->data()->thread_ = pthread_self(); |
489 ASSERT(thread->data()->thread_ != kNoThread); | 490 ASSERT(thread->data()->thread_ != kNoThread); |
490 thread->Run(); | 491 thread->NotifyStartedAndRun(); |
491 return NULL; | 492 return NULL; |
492 } | 493 } |
493 | 494 |
494 | 495 |
495 void Thread::set_name(const char* name) { | 496 void Thread::set_name(const char* name) { |
496 strncpy(name_, name, sizeof(name_)); | 497 strncpy(name_, name, sizeof(name_)); |
497 name_[sizeof(name_) - 1] = '\0'; | 498 name_[sizeof(name_) - 1] = '\0'; |
498 } | 499 } |
499 | 500 |
500 | 501 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 } | 737 } |
737 } | 738 } |
738 | 739 |
739 static void AddActiveSampler(Sampler* sampler) { | 740 static void AddActiveSampler(Sampler* sampler) { |
740 ScopedLock lock(mutex_); | 741 ScopedLock lock(mutex_); |
741 SamplerRegistry::AddActiveSampler(sampler); | 742 SamplerRegistry::AddActiveSampler(sampler); |
742 if (instance_ == NULL) { | 743 if (instance_ == NULL) { |
743 // Start a thread that will send SIGPROF signal to VM threads, | 744 // Start a thread that will send SIGPROF signal to VM threads, |
744 // when CPU profiling will be enabled. | 745 // when CPU profiling will be enabled. |
745 instance_ = new SignalSender(sampler->interval()); | 746 instance_ = new SignalSender(sampler->interval()); |
746 instance_->Start(); | 747 instance_->StartSynchronously(); |
747 } else { | 748 } else { |
748 ASSERT(instance_->interval_ == sampler->interval()); | 749 ASSERT(instance_->interval_ == sampler->interval()); |
749 } | 750 } |
750 } | 751 } |
751 | 752 |
752 static void RemoveActiveSampler(Sampler* sampler) { | 753 static void RemoveActiveSampler(Sampler* sampler) { |
753 ScopedLock lock(mutex_); | 754 ScopedLock lock(mutex_); |
754 SamplerRegistry::RemoveActiveSampler(sampler); | 755 SamplerRegistry::RemoveActiveSampler(sampler); |
755 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 756 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
756 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); | 757 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 } | 867 } |
867 | 868 |
868 | 869 |
869 void Sampler::Stop() { | 870 void Sampler::Stop() { |
870 ASSERT(IsActive()); | 871 ASSERT(IsActive()); |
871 SignalSender::RemoveActiveSampler(this); | 872 SignalSender::RemoveActiveSampler(this); |
872 SetActive(false); | 873 SetActive(false); |
873 } | 874 } |
874 | 875 |
875 } } // namespace v8::internal | 876 } } // namespace v8::internal |
OLD | NEW |