| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 kMmapFd, kMmapFdOffset) != MAP_FAILED; | 391 kMmapFd, kMmapFdOffset) != MAP_FAILED; |
| 392 } | 392 } |
| 393 | 393 |
| 394 | 394 |
| 395 class Thread::PlatformData : public Malloced { | 395 class Thread::PlatformData : public Malloced { |
| 396 public: | 396 public: |
| 397 pthread_t thread_; // Thread handle for pthread. | 397 pthread_t thread_; // Thread handle for pthread. |
| 398 }; | 398 }; |
| 399 | 399 |
| 400 | 400 |
| 401 Thread::Thread(Isolate* isolate, const Options& options) | 401 Thread::Thread(const Options& options) |
| 402 : data_(new PlatformData), | 402 : data_(new PlatformData), |
| 403 isolate_(isolate), | |
| 404 stack_size_(options.stack_size) { | 403 stack_size_(options.stack_size) { |
| 405 set_name(options.name); | 404 set_name(options.name); |
| 406 } | 405 } |
| 407 | 406 |
| 408 | 407 |
| 409 Thread::Thread(Isolate* isolate, const char* name) | 408 Thread::Thread(const char* name) |
| 410 : data_(new PlatformData), | 409 : data_(new PlatformData), |
| 411 isolate_(isolate), | |
| 412 stack_size_(0) { | 410 stack_size_(0) { |
| 413 set_name(name); | 411 set_name(name); |
| 414 } | 412 } |
| 415 | 413 |
| 416 | 414 |
| 417 Thread::~Thread() { | 415 Thread::~Thread() { |
| 418 delete data_; | 416 delete data_; |
| 419 } | 417 } |
| 420 | 418 |
| 421 | 419 |
| 422 static void* ThreadEntry(void* arg) { | 420 static void* ThreadEntry(void* arg) { |
| 423 Thread* thread = reinterpret_cast<Thread*>(arg); | 421 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 424 // This is also initialized by the first argument to pthread_create() but we | 422 // This is also initialized by the first argument to pthread_create() but we |
| 425 // don't know which thread will run first (the original thread or the new | 423 // don't know which thread will run first (the original thread or the new |
| 426 // one) so we initialize it here too. | 424 // one) so we initialize it here too. |
| 427 thread->data()->thread_ = pthread_self(); | 425 thread->data()->thread_ = pthread_self(); |
| 428 ASSERT(thread->data()->thread_ != kNoThread); | 426 ASSERT(thread->data()->thread_ != kNoThread); |
| 429 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); | |
| 430 thread->Run(); | 427 thread->Run(); |
| 431 return NULL; | 428 return NULL; |
| 432 } | 429 } |
| 433 | 430 |
| 434 | 431 |
| 435 void Thread::set_name(const char* name) { | 432 void Thread::set_name(const char* name) { |
| 436 strncpy(name_, name, sizeof(name_)); | 433 strncpy(name_, name, sizeof(name_)); |
| 437 name_[sizeof(name_) - 1] = '\0'; | 434 name_[sizeof(name_) - 1] = '\0'; |
| 438 } | 435 } |
| 439 | 436 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 | 650 |
| 654 | 651 |
| 655 class SignalSender : public Thread { | 652 class SignalSender : public Thread { |
| 656 public: | 653 public: |
| 657 enum SleepInterval { | 654 enum SleepInterval { |
| 658 HALF_INTERVAL, | 655 HALF_INTERVAL, |
| 659 FULL_INTERVAL | 656 FULL_INTERVAL |
| 660 }; | 657 }; |
| 661 | 658 |
| 662 explicit SignalSender(int interval) | 659 explicit SignalSender(int interval) |
| 663 : Thread(NULL, "SignalSender"), | 660 : Thread("SignalSender"), |
| 664 interval_(interval) {} | 661 interval_(interval) {} |
| 665 | 662 |
| 666 static void AddActiveSampler(Sampler* sampler) { | 663 static void AddActiveSampler(Sampler* sampler) { |
| 667 ScopedLock lock(mutex_); | 664 ScopedLock lock(mutex_); |
| 668 SamplerRegistry::AddActiveSampler(sampler); | 665 SamplerRegistry::AddActiveSampler(sampler); |
| 669 if (instance_ == NULL) { | 666 if (instance_ == NULL) { |
| 670 // Install a signal handler. | 667 // Install a signal handler. |
| 671 struct sigaction sa; | 668 struct sigaction sa; |
| 672 sa.sa_sigaction = ProfilerSignalHandler; | 669 sa.sa_sigaction = ProfilerSignalHandler; |
| 673 sigemptyset(&sa.sa_mask); | 670 sigemptyset(&sa.sa_mask); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 | 814 |
| 818 void Sampler::Stop() { | 815 void Sampler::Stop() { |
| 819 ASSERT(IsActive()); | 816 ASSERT(IsActive()); |
| 820 SignalSender::RemoveActiveSampler(this); | 817 SignalSender::RemoveActiveSampler(this); |
| 821 SetActive(false); | 818 SetActive(false); |
| 822 } | 819 } |
| 823 | 820 |
| 824 #endif // ENABLE_LOGGING_AND_PROFILING | 821 #endif // ENABLE_LOGGING_AND_PROFILING |
| 825 | 822 |
| 826 } } // namespace v8::internal | 823 } } // namespace v8::internal |
| OLD | NEW |