| 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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 return pthread_equal(data_->thread_, pthread_self()); | 544 return pthread_equal(data_->thread_, pthread_self()); |
| 545 } | 545 } |
| 546 | 546 |
| 547 | 547 |
| 548 bool ThreadHandle::IsValid() const { | 548 bool ThreadHandle::IsValid() const { |
| 549 return data_->thread_ != kNoThread; | 549 return data_->thread_ != kNoThread; |
| 550 } | 550 } |
| 551 | 551 |
| 552 | 552 |
| 553 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { | 553 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { |
| 554 #ifdef DEBUG_THREAD_NAMES |
| 555 SetName("v8:<unknown>"); |
| 556 #endif |
| 554 } | 557 } |
| 555 | 558 |
| 556 | 559 |
| 560 #ifdef DEBUG_THREAD_NAMES |
| 561 Thread::Thread(const char* name) : ThreadHandle(ThreadHandle::INVALID) { |
| 562 SetName(name); |
| 563 } |
| 564 #endif |
| 565 |
| 566 |
| 557 Thread::~Thread() { | 567 Thread::~Thread() { |
| 558 } | 568 } |
| 559 | 569 |
| 560 | 570 |
| 561 static void* ThreadEntry(void* arg) { | 571 static void* ThreadEntry(void* arg) { |
| 562 Thread* thread = reinterpret_cast<Thread*>(arg); | 572 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 563 // This is also initialized by the first argument to pthread_create() but we | 573 // This is also initialized by the first argument to pthread_create() but we |
| 564 // don't know which thread will run first (the original thread or the new | 574 // don't know which thread will run first (the original thread or the new |
| 565 // one) so we initialize it here too. | 575 // one) so we initialize it here too. |
| 576 #ifdef DEBUG_THREAD_NAMES |
| 577 ::prctl(PR_SET_NAME, thread->Name(), 0, 0, 0); |
| 578 #endif |
| 566 thread->thread_handle_data()->thread_ = pthread_self(); | 579 thread->thread_handle_data()->thread_ = pthread_self(); |
| 567 ASSERT(thread->IsValid()); | 580 ASSERT(thread->IsValid()); |
| 568 thread->Run(); | 581 thread->Run(); |
| 569 return NULL; | 582 return NULL; |
| 570 } | 583 } |
| 571 | 584 |
| 572 | 585 |
| 586 #ifdef DEBUG_THREAD_NAMES |
| 587 void Thread::SetName(const char* name) { |
| 588 strncpy(name_, name, sizeof(name_)); |
| 589 name_[sizeof(name_)-1] = '\0'; |
| 590 } |
| 591 #endif |
| 592 |
| 593 |
| 573 void Thread::Start() { | 594 void Thread::Start() { |
| 574 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); | 595 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); |
| 575 ASSERT(IsValid()); | 596 ASSERT(IsValid()); |
| 576 } | 597 } |
| 577 | 598 |
| 578 | 599 |
| 579 void Thread::Join() { | 600 void Thread::Join() { |
| 580 pthread_join(thread_handle_data()->thread_, NULL); | 601 pthread_join(thread_handle_data()->thread_, NULL); |
| 581 } | 602 } |
| 582 | 603 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 } | 965 } |
| 945 | 966 |
| 946 // This sampler is no longer the active sampler. | 967 // This sampler is no longer the active sampler. |
| 947 active_sampler_ = NULL; | 968 active_sampler_ = NULL; |
| 948 } | 969 } |
| 949 | 970 |
| 950 | 971 |
| 951 #endif // ENABLE_LOGGING_AND_PROFILING | 972 #endif // ENABLE_LOGGING_AND_PROFILING |
| 952 | 973 |
| 953 } } // namespace v8::internal | 974 } } // namespace v8::internal |
| OLD | NEW |