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. |
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'; | |
Søren Thygesen Gjesse
2011/01/03 07:48:34
Please add spaces on both sides of '-'. In all the
marklam
2011/01/04 01:47:09
Done.
| |
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 ASSERT(IsValid()); | 453 ASSERT(IsValid()); |
436 } | 454 } |
437 | 455 |
438 | 456 |
439 void Thread::Join() { | 457 void Thread::Join() { |
440 pthread_join(thread_handle_data()->thread_, NULL); | 458 pthread_join(thread_handle_data()->thread_, NULL); |
441 } | 459 } |
442 | 460 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
667 } | 685 } |
668 | 686 |
669 // This sampler is no longer the active sampler. | 687 // This sampler is no longer the active sampler. |
670 active_sampler_ = NULL; | 688 active_sampler_ = NULL; |
671 active_ = false; | 689 active_ = false; |
672 } | 690 } |
673 | 691 |
674 #endif // ENABLE_LOGGING_AND_PROFILING | 692 #endif // ENABLE_LOGGING_AND_PROFILING |
675 | 693 |
676 } } // namespace v8::internal | 694 } } // namespace v8::internal |
OLD | NEW |