| 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 13 matching lines...) Expand all Loading... |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Platform specific code for Linux goes here. For the POSIX comaptible parts | 28 // Platform specific code for Linux goes here. For the POSIX comaptible parts |
| 29 // the implementation is in platform-posix.cc. | 29 // the implementation is in platform-posix.cc. |
| 30 | 30 |
| 31 #include <pthread.h> | 31 #include <pthread.h> |
| 32 #include <semaphore.h> | 32 #include <semaphore.h> |
| 33 #include <signal.h> | 33 #include <signal.h> |
| 34 #include <sys/prctl.h> |
| 34 #include <sys/time.h> | 35 #include <sys/time.h> |
| 35 #include <sys/resource.h> | 36 #include <sys/resource.h> |
| 36 #include <sys/syscall.h> | 37 #include <sys/syscall.h> |
| 37 #include <sys/types.h> | 38 #include <sys/types.h> |
| 38 #include <stdlib.h> | 39 #include <stdlib.h> |
| 39 | 40 |
| 40 // Ubuntu Dapper requires memory pages to be marked as | 41 // Ubuntu Dapper requires memory pages to be marked as |
| 41 // executable. Otherwise, OS raises an exception when executing code | 42 // executable. Otherwise, OS raises an exception when executing code |
| 42 // in that page. | 43 // in that page. |
| 43 #include <sys/types.h> // mmap & munmap | 44 #include <sys/types.h> // mmap & munmap |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 | 553 |
| 553 | 554 |
| 554 bool ThreadHandle::IsValid() const { | 555 bool ThreadHandle::IsValid() const { |
| 555 return data_->thread_ != kNoThread; | 556 return data_->thread_ != kNoThread; |
| 556 } | 557 } |
| 557 | 558 |
| 558 | 559 |
| 559 Thread::Thread(Isolate* isolate) | 560 Thread::Thread(Isolate* isolate) |
| 560 : ThreadHandle(ThreadHandle::INVALID), | 561 : ThreadHandle(ThreadHandle::INVALID), |
| 561 isolate_(isolate) { | 562 isolate_(isolate) { |
| 563 set_name("v8:<unknown>"); |
| 564 } |
| 565 |
| 566 |
| 567 Thread::Thread(Isolate* isolate, const char* name) |
| 568 : ThreadHandle(ThreadHandle::INVALID), |
| 569 isolate_(isolate) { |
| 570 set_name(name); |
| 562 } | 571 } |
| 563 | 572 |
| 564 | 573 |
| 565 Thread::~Thread() { | 574 Thread::~Thread() { |
| 566 } | 575 } |
| 567 | 576 |
| 568 | 577 |
| 569 static void* ThreadEntry(void* arg) { | 578 static void* ThreadEntry(void* arg) { |
| 570 Thread* thread = reinterpret_cast<Thread*>(arg); | 579 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 571 // This is also initialized by the first argument to pthread_create() but we | 580 // This is also initialized by the first argument to pthread_create() but we |
| 572 // don't know which thread will run first (the original thread or the new | 581 // don't know which thread will run first (the original thread or the new |
| 573 // one) so we initialize it here too. | 582 // one) so we initialize it here too. |
| 583 prctl(PR_SET_NAME, thread->name(), 0, 0, 0); |
| 574 thread->thread_handle_data()->thread_ = pthread_self(); | 584 thread->thread_handle_data()->thread_ = pthread_self(); |
| 575 ASSERT(thread->IsValid()); | 585 ASSERT(thread->IsValid()); |
| 576 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); | 586 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); |
| 577 thread->Run(); | 587 thread->Run(); |
| 578 return NULL; | 588 return NULL; |
| 579 } | 589 } |
| 580 | 590 |
| 581 | 591 |
| 592 void Thread::set_name(const char* name) { |
| 593 strncpy(name_, name, sizeof(name_)); |
| 594 name_[sizeof(name_) - 1] = '\0'; |
| 595 } |
| 596 |
| 597 |
| 582 void Thread::Start() { | 598 void Thread::Start() { |
| 583 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); | 599 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); |
| 584 ASSERT(IsValid()); | 600 ASSERT(IsValid()); |
| 585 } | 601 } |
| 586 | 602 |
| 587 | 603 |
| 588 void Thread::Join() { | 604 void Thread::Join() { |
| 589 pthread_join(thread_handle_data()->thread_, NULL); | 605 pthread_join(thread_handle_data()->thread_, NULL); |
| 590 } | 606 } |
| 591 | 607 |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 | 1011 |
| 996 void Sampler::Stop() { | 1012 void Sampler::Stop() { |
| 997 ASSERT(IsActive()); | 1013 ASSERT(IsActive()); |
| 998 SignalSender::RemoveActiveSampler(this); | 1014 SignalSender::RemoveActiveSampler(this); |
| 999 SetActive(false); | 1015 SetActive(false); |
| 1000 } | 1016 } |
| 1001 | 1017 |
| 1002 #endif // ENABLE_LOGGING_AND_PROFILING | 1018 #endif // ENABLE_LOGGING_AND_PROFILING |
| 1003 | 1019 |
| 1004 } } // namespace v8::internal | 1020 } } // namespace v8::internal |
| OLD | NEW |