Chromium Code Reviews| 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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 return pthread_equal(data_->thread_, pthread_self()); | 404 return pthread_equal(data_->thread_, pthread_self()); |
| 405 } | 405 } |
| 406 | 406 |
| 407 | 407 |
| 408 bool ThreadHandle::IsValid() const { | 408 bool ThreadHandle::IsValid() const { |
| 409 return data_->thread_ != kNoThread; | 409 return data_->thread_ != kNoThread; |
| 410 } | 410 } |
| 411 | 411 |
| 412 | 412 |
| 413 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { | 413 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { |
| 414 #ifdef DEBUG_THREAD_NAMES | |
| 415 SetName("v8:<unknown>"); | |
| 416 #endif | |
| 414 } | 417 } |
| 415 | 418 |
| 416 | 419 |
| 420 #ifdef DEBUG_THREAD_NAMES | |
| 421 Thread::Thread(const char* name) : ThreadHandle(ThreadHandle::INVALID) { | |
| 422 SetName(name); | |
| 423 } | |
| 424 #endif | |
| 425 | |
| 426 | |
| 417 Thread::~Thread() { | 427 Thread::~Thread() { |
| 418 } | 428 } |
| 419 | 429 |
| 420 | 430 |
| 421 static void* ThreadEntry(void* arg) { | 431 static void* ThreadEntry(void* arg) { |
| 422 Thread* thread = reinterpret_cast<Thread*>(arg); | 432 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 423 // This is also initialized by the first argument to pthread_create() but we | 433 // This is also initialized by the first argument to pthread_create() but we |
| 424 // don't know which thread will run first (the original thread or the new | 434 // don't know which thread will run first (the original thread or the new |
| 425 // one) so we initialize it here too. | 435 // one) so we initialize it here too. |
|
Søren Thygesen Gjesse
2011/01/03 07:48:34
Is this not supported on MacOS somehow?
marklam
2011/01/04 01:47:09
There is a pthread_setname_np() but it is not supp
| |
| 426 thread->thread_handle_data()->thread_ = pthread_self(); | 436 thread->thread_handle_data()->thread_ = pthread_self(); |
| 427 ASSERT(thread->IsValid()); | 437 ASSERT(thread->IsValid()); |
| 428 thread->Run(); | 438 thread->Run(); |
| 429 return NULL; | 439 return NULL; |
| 430 } | 440 } |
| 431 | 441 |
| 432 | 442 |
| 443 #ifdef DEBUG_THREAD_NAMES | |
| 444 void Thread::SetName(const char* name) { | |
| 445 strncpy(name_, name, sizeof(name_)); | |
| 446 name_[sizeof(name_)-1] = '\0'; | |
| 447 } | |
| 448 #endif | |
| 449 | |
| 450 | |
| 433 void Thread::Start() { | 451 void Thread::Start() { |
| 434 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); | 452 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); |
| 435 } | 453 } |
| 436 | 454 |
| 437 | 455 |
| 438 void Thread::Join() { | 456 void Thread::Join() { |
| 439 pthread_join(thread_handle_data()->thread_, NULL); | 457 pthread_join(thread_handle_data()->thread_, NULL); |
| 440 } | 458 } |
| 441 | 459 |
| 442 | 460 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 Top::WakeUpRuntimeProfilerThreadBeforeShutdown(); | 696 Top::WakeUpRuntimeProfilerThreadBeforeShutdown(); |
| 679 pthread_join(data_->sampler_thread_, NULL); | 697 pthread_join(data_->sampler_thread_, NULL); |
| 680 | 698 |
| 681 // Deallocate Mach port for thread. | 699 // Deallocate Mach port for thread. |
| 682 mach_port_deallocate(data_->task_self_, data_->profiled_thread_); | 700 mach_port_deallocate(data_->task_self_, data_->profiled_thread_); |
| 683 } | 701 } |
| 684 | 702 |
| 685 #endif // ENABLE_LOGGING_AND_PROFILING | 703 #endif // ENABLE_LOGGING_AND_PROFILING |
| 686 | 704 |
| 687 } } // namespace v8::internal | 705 } } // namespace v8::internal |
| OLD | NEW |