| 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 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 bool ThreadHandle::IsSelf() const { | 566 bool ThreadHandle::IsSelf() const { |
| 567 return pthread_equal(data_->thread_, pthread_self()); | 567 return pthread_equal(data_->thread_, pthread_self()); |
| 568 } | 568 } |
| 569 | 569 |
| 570 | 570 |
| 571 bool ThreadHandle::IsValid() const { | 571 bool ThreadHandle::IsValid() const { |
| 572 return data_->thread_ != kNoThread; | 572 return data_->thread_ != kNoThread; |
| 573 } | 573 } |
| 574 | 574 |
| 575 | 575 |
| 576 Thread::Thread(Isolate* isolate) | 576 Thread::Thread(Isolate* isolate, const Options& options) |
| 577 : ThreadHandle(ThreadHandle::INVALID), | 577 : ThreadHandle(ThreadHandle::INVALID), |
| 578 isolate_(isolate) { | 578 isolate_(isolate), |
| 579 set_name("v8:<unknown>"); | 579 stack_size_(options.stack_size) { |
| 580 set_name(options.name); |
| 580 } | 581 } |
| 581 | 582 |
| 582 | 583 |
| 583 Thread::Thread(Isolate* isolate, const char* name) | 584 Thread::Thread(Isolate* isolate, const char* name) |
| 584 : ThreadHandle(ThreadHandle::INVALID), | 585 : ThreadHandle(ThreadHandle::INVALID), |
| 585 isolate_(isolate) { | 586 isolate_(isolate), |
| 587 stack_size_(0) { |
| 586 set_name(name); | 588 set_name(name); |
| 587 } | 589 } |
| 588 | 590 |
| 589 | 591 |
| 590 Thread::~Thread() { | 592 Thread::~Thread() { |
| 591 } | 593 } |
| 592 | 594 |
| 593 | 595 |
| 594 static void* ThreadEntry(void* arg) { | 596 static void* ThreadEntry(void* arg) { |
| 595 Thread* thread = reinterpret_cast<Thread*>(arg); | 597 Thread* thread = reinterpret_cast<Thread*>(arg); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 607 } | 609 } |
| 608 | 610 |
| 609 | 611 |
| 610 void Thread::set_name(const char* name) { | 612 void Thread::set_name(const char* name) { |
| 611 strncpy(name_, name, sizeof(name_)); | 613 strncpy(name_, name, sizeof(name_)); |
| 612 name_[sizeof(name_) - 1] = '\0'; | 614 name_[sizeof(name_) - 1] = '\0'; |
| 613 } | 615 } |
| 614 | 616 |
| 615 | 617 |
| 616 void Thread::Start() { | 618 void Thread::Start() { |
| 617 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); | 619 pthread_attr_t* attr_ptr = NULL; |
| 620 pthread_attr_t attr; |
| 621 if (stack_size_ > 0) { |
| 622 pthread_attr_init(&attr); |
| 623 pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); |
| 624 attr_ptr = &attr; |
| 625 } |
| 626 pthread_create(&thread_handle_data()->thread_, attr_ptr, ThreadEntry, this); |
| 618 ASSERT(IsValid()); | 627 ASSERT(IsValid()); |
| 619 } | 628 } |
| 620 | 629 |
| 621 | 630 |
| 622 void Thread::Join() { | 631 void Thread::Join() { |
| 623 pthread_join(thread_handle_data()->thread_, NULL); | 632 pthread_join(thread_handle_data()->thread_, NULL); |
| 624 } | 633 } |
| 625 | 634 |
| 626 | 635 |
| 627 Thread::LocalStorageKey Thread::CreateThreadLocalKey() { | 636 Thread::LocalStorageKey Thread::CreateThreadLocalKey() { |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 | 877 |
| 869 | 878 |
| 870 class SignalSender : public Thread { | 879 class SignalSender : public Thread { |
| 871 public: | 880 public: |
| 872 enum SleepInterval { | 881 enum SleepInterval { |
| 873 HALF_INTERVAL, | 882 HALF_INTERVAL, |
| 874 FULL_INTERVAL | 883 FULL_INTERVAL |
| 875 }; | 884 }; |
| 876 | 885 |
| 877 explicit SignalSender(int interval) | 886 explicit SignalSender(int interval) |
| 878 : Thread(NULL), vm_tgid_(getpid()), interval_(interval) {} | 887 : Thread(NULL, "SignalSender"), |
| 888 vm_tgid_(getpid()), |
| 889 interval_(interval) {} |
| 879 | 890 |
| 880 static void AddActiveSampler(Sampler* sampler) { | 891 static void AddActiveSampler(Sampler* sampler) { |
| 881 ScopedLock lock(mutex_); | 892 ScopedLock lock(mutex_); |
| 882 SamplerRegistry::AddActiveSampler(sampler); | 893 SamplerRegistry::AddActiveSampler(sampler); |
| 883 if (instance_ == NULL) { | 894 if (instance_ == NULL) { |
| 884 // Install a signal handler. | 895 // Install a signal handler. |
| 885 struct sigaction sa; | 896 struct sigaction sa; |
| 886 sa.sa_sigaction = ProfilerSignalHandler; | 897 sa.sa_sigaction = ProfilerSignalHandler; |
| 887 sigemptyset(&sa.sa_mask); | 898 sigemptyset(&sa.sa_mask); |
| 888 sa.sa_flags = SA_RESTART | SA_SIGINFO; | 899 sa.sa_flags = SA_RESTART | SA_SIGINFO; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 | 1044 |
| 1034 void Sampler::Stop() { | 1045 void Sampler::Stop() { |
| 1035 ASSERT(IsActive()); | 1046 ASSERT(IsActive()); |
| 1036 SignalSender::RemoveActiveSampler(this); | 1047 SignalSender::RemoveActiveSampler(this); |
| 1037 SetActive(false); | 1048 SetActive(false); |
| 1038 } | 1049 } |
| 1039 | 1050 |
| 1040 #endif // ENABLE_LOGGING_AND_PROFILING | 1051 #endif // ENABLE_LOGGING_AND_PROFILING |
| 1041 | 1052 |
| 1042 } } // namespace v8::internal | 1053 } } // namespace v8::internal |
| OLD | NEW |