| 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 return pthread_equal(data_->thread_, pthread_self()); | 380 return pthread_equal(data_->thread_, pthread_self()); |
| 381 } | 381 } |
| 382 | 382 |
| 383 | 383 |
| 384 bool ThreadHandle::IsValid() const { | 384 bool ThreadHandle::IsValid() const { |
| 385 return data_->thread_ != kNoThread; | 385 return data_->thread_ != kNoThread; |
| 386 } | 386 } |
| 387 | 387 |
| 388 | 388 |
| 389 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { | 389 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { |
| 390 #ifdef DEBUG_THREAD_NAMES |
| 391 SetName("v8:<unknown>"); |
| 392 #endif |
| 390 } | 393 } |
| 391 | 394 |
| 392 | 395 |
| 396 #ifdef DEBUG_THREAD_NAMES |
| 397 Thread::Thread(const char* name) : ThreadHandle(ThreadHandle::INVALID) { |
| 398 SetName(name); |
| 399 } |
| 400 #endif |
| 401 |
| 402 |
| 393 Thread::~Thread() { | 403 Thread::~Thread() { |
| 394 } | 404 } |
| 395 | 405 |
| 396 | 406 |
| 397 static void* ThreadEntry(void* arg) { | 407 static void* ThreadEntry(void* arg) { |
| 398 Thread* thread = reinterpret_cast<Thread*>(arg); | 408 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 399 // This is also initialized by the first argument to pthread_create() but we | 409 // This is also initialized by the first argument to pthread_create() but we |
| 400 // don't know which thread will run first (the original thread or the new | 410 // don't know which thread will run first (the original thread or the new |
| 401 // one) so we initialize it here too. | 411 // one) so we initialize it here too. |
| 402 thread->thread_handle_data()->thread_ = pthread_self(); | 412 thread->thread_handle_data()->thread_ = pthread_self(); |
| 403 ASSERT(thread->IsValid()); | 413 ASSERT(thread->IsValid()); |
| 404 thread->Run(); | 414 thread->Run(); |
| 405 return NULL; | 415 return NULL; |
| 406 } | 416 } |
| 407 | 417 |
| 408 | 418 |
| 419 #ifdef DEBUG_THREAD_NAMES |
| 420 void Thread::SetName(const char* name) { |
| 421 strncpy(name_, name, sizeof(name_)); |
| 422 name_[sizeof(name_)-1] = '\0'; |
| 423 } |
| 424 #endif |
| 425 |
| 426 |
| 409 void Thread::Start() { | 427 void Thread::Start() { |
| 410 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); | 428 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); |
| 411 ASSERT(IsValid()); | 429 ASSERT(IsValid()); |
| 412 } | 430 } |
| 413 | 431 |
| 414 | 432 |
| 415 void Thread::Join() { | 433 void Thread::Join() { |
| 416 pthread_join(thread_handle_data()->thread_, NULL); | 434 pthread_join(thread_handle_data()->thread_, NULL); |
| 417 } | 435 } |
| 418 | 436 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 } | 640 } |
| 623 | 641 |
| 624 // This sampler is no longer the active sampler. | 642 // This sampler is no longer the active sampler. |
| 625 active_sampler_ = NULL; | 643 active_sampler_ = NULL; |
| 626 active_ = false; | 644 active_ = false; |
| 627 } | 645 } |
| 628 | 646 |
| 629 #endif // ENABLE_LOGGING_AND_PROFILING | 647 #endif // ENABLE_LOGGING_AND_PROFILING |
| 630 | 648 |
| 631 } } // namespace v8::internal | 649 } } // namespace v8::internal |
| OLD | NEW |