| 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 class Thread::PlatformData : public Malloced { | 358 class Thread::PlatformData : public Malloced { |
| 359 public: | 359 public: |
| 360 PlatformData() : thread_(kNoThread) {} | 360 PlatformData() : thread_(kNoThread) {} |
| 361 pthread_t thread_; // Thread handle for pthread. | 361 pthread_t thread_; // Thread handle for pthread. |
| 362 }; | 362 }; |
| 363 | 363 |
| 364 | 364 |
| 365 | 365 |
| 366 | 366 |
| 367 Thread::Thread(const Options& options) | 367 Thread::Thread(const Options& options) |
| 368 : data_(new PlatformData), | 368 : data_(new PlatformData()), |
| 369 stack_size_(options.stack_size) { | 369 stack_size_(options.stack_size()) { |
| 370 set_name(options.name); | 370 set_name(options.name()); |
| 371 } | 371 } |
| 372 | 372 |
| 373 | 373 |
| 374 Thread::Thread(const char* name) | |
| 375 : data_(new PlatformData), | |
| 376 stack_size_(0) { | |
| 377 set_name(name); | |
| 378 } | |
| 379 | |
| 380 | |
| 381 Thread::~Thread() { | 374 Thread::~Thread() { |
| 382 delete data_; | 375 delete data_; |
| 383 } | 376 } |
| 384 | 377 |
| 385 | 378 |
| 386 static void* ThreadEntry(void* arg) { | 379 static void* ThreadEntry(void* arg) { |
| 387 Thread* thread = reinterpret_cast<Thread*>(arg); | 380 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 388 // This is also initialized by the first argument to pthread_create() but we | 381 // This is also initialized by the first argument to pthread_create() but we |
| 389 // don't know which thread will run first (the original thread or the new | 382 // don't know which thread will run first (the original thread or the new |
| 390 // one) so we initialize it here too. | 383 // one) so we initialize it here too. |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 | 603 |
| 611 HANDLE profiled_thread() { return profiled_thread_; } | 604 HANDLE profiled_thread() { return profiled_thread_; } |
| 612 | 605 |
| 613 private: | 606 private: |
| 614 HANDLE profiled_thread_; | 607 HANDLE profiled_thread_; |
| 615 }; | 608 }; |
| 616 | 609 |
| 617 | 610 |
| 618 class SamplerThread : public Thread { | 611 class SamplerThread : public Thread { |
| 619 public: | 612 public: |
| 613 static const int kSamplerThreadStackSize = 64 * KB; |
| 614 |
| 620 explicit SamplerThread(int interval) | 615 explicit SamplerThread(int interval) |
| 621 : Thread("SamplerThread"), | 616 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), |
| 622 interval_(interval) {} | 617 interval_(interval) {} |
| 623 | 618 |
| 624 static void AddActiveSampler(Sampler* sampler) { | 619 static void AddActiveSampler(Sampler* sampler) { |
| 625 ScopedLock lock(mutex_); | 620 ScopedLock lock(mutex_); |
| 626 SamplerRegistry::AddActiveSampler(sampler); | 621 SamplerRegistry::AddActiveSampler(sampler); |
| 627 if (instance_ == NULL) { | 622 if (instance_ == NULL) { |
| 628 instance_ = new SamplerThread(sampler->interval()); | 623 instance_ = new SamplerThread(sampler->interval()); |
| 629 instance_->Start(); | 624 instance_->Start(); |
| 630 } else { | 625 } else { |
| 631 ASSERT(instance_->interval_ == sampler->interval()); | 626 ASSERT(instance_->interval_ == sampler->interval()); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 | 750 |
| 756 | 751 |
| 757 void Sampler::Stop() { | 752 void Sampler::Stop() { |
| 758 ASSERT(IsActive()); | 753 ASSERT(IsActive()); |
| 759 SamplerThread::RemoveActiveSampler(this); | 754 SamplerThread::RemoveActiveSampler(this); |
| 760 SetActive(false); | 755 SetActive(false); |
| 761 } | 756 } |
| 762 | 757 |
| 763 | 758 |
| 764 } } // namespace v8::internal | 759 } } // namespace v8::internal |
| OLD | NEW |