| 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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(Isolate* isolate) | 413 Thread::Thread(Isolate* isolate) |
| 414 : ThreadHandle(ThreadHandle::INVALID), | 414 : ThreadHandle(ThreadHandle::INVALID), |
| 415 isolate_(isolate) { | 415 isolate_(isolate) { |
| 416 set_name("v8:<unknown>"); |
| 417 } |
| 418 |
| 419 Thread::Thread(Isolate* isolate, const char* name) |
| 420 : ThreadHandle(ThreadHandle::INVALID), |
| 421 isolate_(isolate) { |
| 422 set_name(name); |
| 416 } | 423 } |
| 417 | 424 |
| 418 | 425 |
| 419 Thread::~Thread() { | 426 Thread::~Thread() { |
| 420 } | 427 } |
| 421 | 428 |
| 422 | 429 |
| 423 static void* ThreadEntry(void* arg) { | 430 static void* ThreadEntry(void* arg) { |
| 424 Thread* thread = reinterpret_cast<Thread*>(arg); | 431 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 425 // This is also initialized by the first argument to pthread_create() but we | 432 // This is also initialized by the first argument to pthread_create() but we |
| 426 // don't know which thread will run first (the original thread or the new | 433 // don't know which thread will run first (the original thread or the new |
| 427 // one) so we initialize it here too. | 434 // one) so we initialize it here too. |
| 428 thread->thread_handle_data()->thread_ = pthread_self(); | 435 thread->thread_handle_data()->thread_ = pthread_self(); |
| 429 ASSERT(thread->IsValid()); | 436 ASSERT(thread->IsValid()); |
| 430 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); | 437 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); |
| 431 thread->Run(); | 438 thread->Run(); |
| 432 return NULL; | 439 return NULL; |
| 433 } | 440 } |
| 434 | 441 |
| 435 | 442 |
| 443 void Thread::set_name(const char* name) { |
| 444 strncpy(name_, name, sizeof(name_)); |
| 445 name_[sizeof(name_) - 1] = '\0'; |
| 446 } |
| 447 |
| 448 |
| 436 void Thread::Start() { | 449 void Thread::Start() { |
| 437 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); | 450 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); |
| 438 ASSERT(IsValid()); | 451 ASSERT(IsValid()); |
| 439 } | 452 } |
| 440 | 453 |
| 441 | 454 |
| 442 void Thread::Join() { | 455 void Thread::Join() { |
| 443 pthread_join(thread_handle_data()->thread_, NULL); | 456 pthread_join(thread_handle_data()->thread_, NULL); |
| 444 } | 457 } |
| 445 | 458 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 } | 684 } |
| 672 | 685 |
| 673 // This sampler is no longer the active sampler. | 686 // This sampler is no longer the active sampler. |
| 674 active_sampler_ = NULL; | 687 active_sampler_ = NULL; |
| 675 active_ = false; | 688 active_ = false; |
| 676 } | 689 } |
| 677 | 690 |
| 678 #endif // ENABLE_LOGGING_AND_PROFILING | 691 #endif // ENABLE_LOGGING_AND_PROFILING |
| 679 | 692 |
| 680 } } // namespace v8::internal | 693 } } // namespace v8::internal |
| OLD | NEW |