| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 return pthread_equal(data_->thread_, pthread_self()); | 394 return pthread_equal(data_->thread_, pthread_self()); |
| 395 } | 395 } |
| 396 | 396 |
| 397 | 397 |
| 398 bool ThreadHandle::IsValid() const { | 398 bool ThreadHandle::IsValid() const { |
| 399 return data_->thread_ != kNoThread; | 399 return data_->thread_ != kNoThread; |
| 400 } | 400 } |
| 401 | 401 |
| 402 | 402 |
| 403 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { | 403 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { |
| 404 #ifdef DEBUG_THREAD_NAMES |
| 405 SetName("v8:<unknown>"); |
| 406 #endif |
| 404 } | 407 } |
| 405 | 408 |
| 406 | 409 |
| 410 #ifdef DEBUG_THREAD_NAMES |
| 411 Thread::Thread(const char* name) : ThreadHandle(ThreadHandle::INVALID) { |
| 412 SetName(name); |
| 413 } |
| 414 #endif |
| 415 |
| 416 |
| 407 Thread::~Thread() { | 417 Thread::~Thread() { |
| 408 } | 418 } |
| 409 | 419 |
| 410 | 420 |
| 411 static void* ThreadEntry(void* arg) { | 421 static void* ThreadEntry(void* arg) { |
| 412 Thread* thread = reinterpret_cast<Thread*>(arg); | 422 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 413 // This is also initialized by the first argument to pthread_create() but we | 423 // This is also initialized by the first argument to pthread_create() but we |
| 414 // don't know which thread will run first (the original thread or the new | 424 // don't know which thread will run first (the original thread or the new |
| 415 // one) so we initialize it here too. | 425 // one) so we initialize it here too. |
| 416 thread->thread_handle_data()->thread_ = pthread_self(); | 426 thread->thread_handle_data()->thread_ = pthread_self(); |
| 417 ASSERT(thread->IsValid()); | 427 ASSERT(thread->IsValid()); |
| 418 thread->Run(); | 428 thread->Run(); |
| 419 return NULL; | 429 return NULL; |
| 420 } | 430 } |
| 421 | 431 |
| 422 | 432 |
| 433 #ifdef DEBUG_THREAD_NAMES |
| 434 void Thread::SetName(const char* name) { |
| 435 strncpy(name_, name, sizeof(name_)); |
| 436 name_[sizeof(name_)-1] = '\0'; |
| 437 } |
| 438 #endif |
| 439 |
| 440 |
| 423 void Thread::Start() { | 441 void Thread::Start() { |
| 424 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); | 442 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); |
| 425 ASSERT(IsValid()); | 443 ASSERT(IsValid()); |
| 426 } | 444 } |
| 427 | 445 |
| 428 | 446 |
| 429 void Thread::Join() { | 447 void Thread::Join() { |
| 430 pthread_join(thread_handle_data()->thread_, NULL); | 448 pthread_join(thread_handle_data()->thread_, NULL); |
| 431 } | 449 } |
| 432 | 450 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 } | 670 } |
| 653 | 671 |
| 654 // This sampler is no longer the active sampler. | 672 // This sampler is no longer the active sampler. |
| 655 active_sampler_ = NULL; | 673 active_sampler_ = NULL; |
| 656 active_ = false; | 674 active_ = false; |
| 657 } | 675 } |
| 658 | 676 |
| 659 #endif // ENABLE_LOGGING_AND_PROFILING | 677 #endif // ENABLE_LOGGING_AND_PROFILING |
| 660 | 678 |
| 661 } } // namespace v8::internal | 679 } } // namespace v8::internal |
| OLD | NEW |