OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 return munmap(address, size) == 0; | 466 return munmap(address, size) == 0; |
467 } | 467 } |
468 | 468 |
469 | 469 |
470 class Thread::PlatformData : public Malloced { | 470 class Thread::PlatformData : public Malloced { |
471 public: | 471 public: |
472 PlatformData() : thread_(kNoThread) {} | 472 PlatformData() : thread_(kNoThread) {} |
473 pthread_t thread_; // Thread handle for pthread. | 473 pthread_t thread_; // Thread handle for pthread. |
474 }; | 474 }; |
475 | 475 |
476 | |
477 Thread::Thread(const Options& options) | 476 Thread::Thread(const Options& options) |
478 : data_(new PlatformData), | 477 : data_(new PlatformData), |
479 stack_size_(options.stack_size()) { | 478 stack_size_(options.stack_size) { |
480 set_name(options.name()); | 479 set_name(options.name); |
| 480 } |
| 481 |
| 482 |
| 483 Thread::Thread(const char* name) |
| 484 : data_(new PlatformData), |
| 485 stack_size_(0) { |
| 486 set_name(name); |
481 } | 487 } |
482 | 488 |
483 | 489 |
484 Thread::~Thread() { | 490 Thread::~Thread() { |
485 delete data_; | 491 delete data_; |
486 } | 492 } |
487 | 493 |
488 | 494 |
489 static void SetThreadName(const char* name) { | 495 static void SetThreadName(const char* name) { |
490 // pthread_setname_np is only available in 10.6 or later, so test | 496 // pthread_setname_np is only available in 10.6 or later, so test |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 | 729 |
724 thread_act_t profiled_thread() { return profiled_thread_; } | 730 thread_act_t profiled_thread() { return profiled_thread_; } |
725 | 731 |
726 private: | 732 private: |
727 // Note: for profiled_thread_ Mach primitives are used instead of PThread's | 733 // Note: for profiled_thread_ Mach primitives are used instead of PThread's |
728 // because the latter doesn't provide thread manipulation primitives required. | 734 // because the latter doesn't provide thread manipulation primitives required. |
729 // For details, consult "Mac OS X Internals" book, Section 7.3. | 735 // For details, consult "Mac OS X Internals" book, Section 7.3. |
730 thread_act_t profiled_thread_; | 736 thread_act_t profiled_thread_; |
731 }; | 737 }; |
732 | 738 |
733 | |
734 class SamplerThread : public Thread { | 739 class SamplerThread : public Thread { |
735 public: | 740 public: |
736 static const int kSamplerThreadStackSize = 32 * KB; | |
737 | |
738 explicit SamplerThread(int interval) | 741 explicit SamplerThread(int interval) |
739 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), | 742 : Thread("SamplerThread"), |
740 interval_(interval) {} | 743 interval_(interval) {} |
741 | 744 |
742 static void AddActiveSampler(Sampler* sampler) { | 745 static void AddActiveSampler(Sampler* sampler) { |
743 ScopedLock lock(mutex_); | 746 ScopedLock lock(mutex_); |
744 SamplerRegistry::AddActiveSampler(sampler); | 747 SamplerRegistry::AddActiveSampler(sampler); |
745 if (instance_ == NULL) { | 748 if (instance_ == NULL) { |
746 instance_ = new SamplerThread(sampler->interval()); | 749 instance_ = new SamplerThread(sampler->interval()); |
747 instance_->Start(); | 750 instance_->Start(); |
748 } else { | 751 } else { |
749 ASSERT(instance_->interval_ == sampler->interval()); | 752 ASSERT(instance_->interval_ == sampler->interval()); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 | 888 |
886 | 889 |
887 void Sampler::Stop() { | 890 void Sampler::Stop() { |
888 ASSERT(IsActive()); | 891 ASSERT(IsActive()); |
889 SamplerThread::RemoveActiveSampler(this); | 892 SamplerThread::RemoveActiveSampler(this); |
890 SetActive(false); | 893 SetActive(false); |
891 } | 894 } |
892 | 895 |
893 | 896 |
894 } } // namespace v8::internal | 897 } } // namespace v8::internal |
OLD | NEW |