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