| OLD | NEW |
| 1 // Copyright 2006-2011 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 364 |
| 365 class Thread::PlatformData : public Malloced { | 365 class Thread::PlatformData : public Malloced { |
| 366 public: | 366 public: |
| 367 PlatformData() : thread_(kNoThread) {} | 367 PlatformData() : thread_(kNoThread) {} |
| 368 pthread_t thread_; // Thread handle for pthread. | 368 pthread_t thread_; // Thread handle for pthread. |
| 369 }; | 369 }; |
| 370 | 370 |
| 371 | 371 |
| 372 | 372 |
| 373 | 373 |
| 374 Thread::Thread(Isolate* isolate, const Options& options) | 374 Thread::Thread(const Options& options) |
| 375 : data_(new PlatformData), | 375 : data_(new PlatformData), |
| 376 isolate_(isolate), | |
| 377 stack_size_(options.stack_size) { | 376 stack_size_(options.stack_size) { |
| 378 set_name(options.name); | 377 set_name(options.name); |
| 379 } | 378 } |
| 380 | 379 |
| 381 | 380 |
| 382 Thread::Thread(Isolate* isolate, const char* name) | 381 Thread::Thread(const char* name) |
| 383 : data_(new PlatformData), | 382 : data_(new PlatformData), |
| 384 isolate_(isolate), | |
| 385 stack_size_(0) { | 383 stack_size_(0) { |
| 386 set_name(name); | 384 set_name(name); |
| 387 } | 385 } |
| 388 | 386 |
| 389 | 387 |
| 390 Thread::~Thread() { | 388 Thread::~Thread() { |
| 391 delete data_; | 389 delete data_; |
| 392 } | 390 } |
| 393 | 391 |
| 394 | 392 |
| 395 static void* ThreadEntry(void* arg) { | 393 static void* ThreadEntry(void* arg) { |
| 396 Thread* thread = reinterpret_cast<Thread*>(arg); | 394 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 397 // This is also initialized by the first argument to pthread_create() but we | 395 // This is also initialized by the first argument to pthread_create() but we |
| 398 // don't know which thread will run first (the original thread or the new | 396 // don't know which thread will run first (the original thread or the new |
| 399 // one) so we initialize it here too. | 397 // one) so we initialize it here too. |
| 400 thread->data()->thread_ = pthread_self(); | 398 thread->data()->thread_ = pthread_self(); |
| 401 ASSERT(thread->data()->thread_ != kNoThread); | 399 ASSERT(thread->data()->thread_ != kNoThread); |
| 402 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); | |
| 403 thread->Run(); | 400 thread->Run(); |
| 404 return NULL; | 401 return NULL; |
| 405 } | 402 } |
| 406 | 403 |
| 407 | 404 |
| 408 void Thread::set_name(const char* name) { | 405 void Thread::set_name(const char* name) { |
| 409 strncpy(name_, name, sizeof(name_)); | 406 strncpy(name_, name, sizeof(name_)); |
| 410 name_[sizeof(name_) - 1] = '\0'; | 407 name_[sizeof(name_) - 1] = '\0'; |
| 411 } | 408 } |
| 412 | 409 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 HANDLE profiled_thread() { return profiled_thread_; } | 621 HANDLE profiled_thread() { return profiled_thread_; } |
| 625 | 622 |
| 626 private: | 623 private: |
| 627 HANDLE profiled_thread_; | 624 HANDLE profiled_thread_; |
| 628 }; | 625 }; |
| 629 | 626 |
| 630 | 627 |
| 631 class SamplerThread : public Thread { | 628 class SamplerThread : public Thread { |
| 632 public: | 629 public: |
| 633 explicit SamplerThread(int interval) | 630 explicit SamplerThread(int interval) |
| 634 : Thread(NULL, "SamplerThread"), | 631 : Thread("SamplerThread"), |
| 635 interval_(interval) {} | 632 interval_(interval) {} |
| 636 | 633 |
| 637 static void AddActiveSampler(Sampler* sampler) { | 634 static void AddActiveSampler(Sampler* sampler) { |
| 638 ScopedLock lock(mutex_); | 635 ScopedLock lock(mutex_); |
| 639 SamplerRegistry::AddActiveSampler(sampler); | 636 SamplerRegistry::AddActiveSampler(sampler); |
| 640 if (instance_ == NULL) { | 637 if (instance_ == NULL) { |
| 641 instance_ = new SamplerThread(sampler->interval()); | 638 instance_ = new SamplerThread(sampler->interval()); |
| 642 instance_->Start(); | 639 instance_->Start(); |
| 643 } else { | 640 } else { |
| 644 ASSERT(instance_->interval_ == sampler->interval()); | 641 ASSERT(instance_->interval_ == sampler->interval()); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 void Sampler::Stop() { | 767 void Sampler::Stop() { |
| 771 ASSERT(IsActive()); | 768 ASSERT(IsActive()); |
| 772 SamplerThread::RemoveActiveSampler(this); | 769 SamplerThread::RemoveActiveSampler(this); |
| 773 SetActive(false); | 770 SetActive(false); |
| 774 } | 771 } |
| 775 | 772 |
| 776 #endif // ENABLE_LOGGING_AND_PROFILING | 773 #endif // ENABLE_LOGGING_AND_PROFILING |
| 777 | 774 |
| 778 } } // namespace v8::internal | 775 } } // namespace v8::internal |
| 779 | 776 |
| OLD | NEW |