| 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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 return pthread_equal(data_->thread_, pthread_self()); | 578 return pthread_equal(data_->thread_, pthread_self()); |
| 578 } | 579 } |
| 579 | 580 |
| 580 | 581 |
| 581 bool ThreadHandle::IsValid() const { | 582 bool ThreadHandle::IsValid() const { |
| 582 return data_->thread_ != kNoThread; | 583 return data_->thread_ != kNoThread; |
| 583 } | 584 } |
| 584 | 585 |
| 585 | 586 |
| 586 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { | 587 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { |
| 588 set_name("v8:<unknown>"); |
| 589 } |
| 590 |
| 591 |
| 592 Thread::Thread(const char* name) : ThreadHandle(ThreadHandle::INVALID) { |
| 593 set_name(name); |
| 587 } | 594 } |
| 588 | 595 |
| 589 | 596 |
| 590 Thread::~Thread() { | 597 Thread::~Thread() { |
| 591 } | 598 } |
| 592 | 599 |
| 593 | 600 |
| 594 static void* ThreadEntry(void* arg) { | 601 static void* ThreadEntry(void* arg) { |
| 595 Thread* thread = reinterpret_cast<Thread*>(arg); | 602 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 596 // This is also initialized by the first argument to pthread_create() but we | 603 // This is also initialized by the first argument to pthread_create() but we |
| 597 // don't know which thread will run first (the original thread or the new | 604 // don't know which thread will run first (the original thread or the new |
| 598 // one) so we initialize it here too. | 605 // one) so we initialize it here too. |
| 606 prctl(PR_SET_NAME, thread->name(), 0, 0, 0); |
| 599 thread->thread_handle_data()->thread_ = pthread_self(); | 607 thread->thread_handle_data()->thread_ = pthread_self(); |
| 600 ASSERT(thread->IsValid()); | 608 ASSERT(thread->IsValid()); |
| 601 thread->Run(); | 609 thread->Run(); |
| 602 return NULL; | 610 return NULL; |
| 603 } | 611 } |
| 604 | 612 |
| 605 | 613 |
| 614 void Thread::set_name(const char* name) { |
| 615 strncpy(name_, name, sizeof(name_)); |
| 616 name_[sizeof(name_) - 1] = '\0'; |
| 617 } |
| 618 |
| 619 |
| 606 void Thread::Start() { | 620 void Thread::Start() { |
| 607 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); | 621 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); |
| 608 ASSERT(IsValid()); | 622 ASSERT(IsValid()); |
| 609 } | 623 } |
| 610 | 624 |
| 611 | 625 |
| 612 void Thread::Join() { | 626 void Thread::Join() { |
| 613 pthread_join(thread_handle_data()->thread_, NULL); | 627 pthread_join(thread_handle_data()->thread_, NULL); |
| 614 } | 628 } |
| 615 | 629 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 } | 991 } |
| 978 | 992 |
| 979 // This sampler is no longer the active sampler. | 993 // This sampler is no longer the active sampler. |
| 980 active_sampler_ = NULL; | 994 active_sampler_ = NULL; |
| 981 } | 995 } |
| 982 | 996 |
| 983 | 997 |
| 984 #endif // ENABLE_LOGGING_AND_PROFILING | 998 #endif // ENABLE_LOGGING_AND_PROFILING |
| 985 | 999 |
| 986 } } // namespace v8::internal | 1000 } } // namespace v8::internal |
| OLD | NEW |