| 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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 425 bool ThreadHandle::IsSelf() const { | 425 bool ThreadHandle::IsSelf() const { | 
| 426   return pthread_equal(data_->thread_, pthread_self()); | 426   return pthread_equal(data_->thread_, pthread_self()); | 
| 427 } | 427 } | 
| 428 | 428 | 
| 429 | 429 | 
| 430 bool ThreadHandle::IsValid() const { | 430 bool ThreadHandle::IsValid() const { | 
| 431   return data_->thread_ != kNoThread; | 431   return data_->thread_ != kNoThread; | 
| 432 } | 432 } | 
| 433 | 433 | 
| 434 | 434 | 
| 435 Thread::Thread(Isolate* isolate) | 435 Thread::Thread(Isolate* isolate, const Options& options) | 
| 436     : ThreadHandle(ThreadHandle::INVALID), | 436     : ThreadHandle(ThreadHandle::INVALID), | 
| 437       isolate_(isolate) { | 437       isolate_(isolate), | 
| 438   set_name("v8:<unknown>"); | 438       stack_size_(options.stack_size) { | 
|  | 439   set_name(options.name); | 
| 439 } | 440 } | 
| 440 | 441 | 
| 441 | 442 | 
| 442 Thread::Thread(Isolate* isolate, const char* name) | 443 Thread::Thread(Isolate* isolate, const char* name) | 
| 443     : ThreadHandle(ThreadHandle::INVALID), | 444     : ThreadHandle(ThreadHandle::INVALID), | 
| 444       isolate_(isolate) { | 445       isolate_(isolate), | 
|  | 446       stack_size_(0) { | 
| 445   set_name(name); | 447   set_name(name); | 
| 446 } | 448 } | 
| 447 | 449 | 
| 448 | 450 | 
| 449 Thread::~Thread() { | 451 Thread::~Thread() { | 
| 450 } | 452 } | 
| 451 | 453 | 
| 452 | 454 | 
| 453 |  | 
| 454 static void SetThreadName(const char* name) { | 455 static void SetThreadName(const char* name) { | 
| 455   // pthread_setname_np is only available in 10.6 or later, so test | 456   // pthread_setname_np is only available in 10.6 or later, so test | 
| 456   // for it at runtime. | 457   // for it at runtime. | 
| 457   int (*dynamic_pthread_setname_np)(const char*); | 458   int (*dynamic_pthread_setname_np)(const char*); | 
| 458   *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = | 459   *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = | 
| 459     dlsym(RTLD_DEFAULT, "pthread_setname_np"); | 460     dlsym(RTLD_DEFAULT, "pthread_setname_np"); | 
| 460   if (!dynamic_pthread_setname_np) | 461   if (!dynamic_pthread_setname_np) | 
| 461     return; | 462     return; | 
| 462 | 463 | 
| 463   // Mac OS X does not expose the length limit of the name, so hardcode it. | 464   // Mac OS X does not expose the length limit of the name, so hardcode it. | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 482 } | 483 } | 
| 483 | 484 | 
| 484 | 485 | 
| 485 void Thread::set_name(const char* name) { | 486 void Thread::set_name(const char* name) { | 
| 486   strncpy(name_, name, sizeof(name_)); | 487   strncpy(name_, name, sizeof(name_)); | 
| 487   name_[sizeof(name_) - 1] = '\0'; | 488   name_[sizeof(name_) - 1] = '\0'; | 
| 488 } | 489 } | 
| 489 | 490 | 
| 490 | 491 | 
| 491 void Thread::Start() { | 492 void Thread::Start() { | 
| 492   pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); | 493   pthread_attr_t* attr_ptr = NULL; | 
|  | 494   pthread_attr_t attr; | 
|  | 495   if (stack_size_ > 0) { | 
|  | 496     pthread_attr_init(&attr); | 
|  | 497     pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); | 
|  | 498     attr_ptr = &attr; | 
|  | 499   } | 
|  | 500   pthread_create(&thread_handle_data()->thread_, attr_ptr, ThreadEntry, this); | 
|  | 501   ASSERT(IsValid()); | 
| 493 } | 502 } | 
| 494 | 503 | 
| 495 | 504 | 
| 496 void Thread::Join() { | 505 void Thread::Join() { | 
| 497   pthread_join(thread_handle_data()->thread_, NULL); | 506   pthread_join(thread_handle_data()->thread_, NULL); | 
| 498 } | 507 } | 
| 499 | 508 | 
| 500 | 509 | 
| 501 Thread::LocalStorageKey Thread::CreateThreadLocalKey() { | 510 Thread::LocalStorageKey Thread::CreateThreadLocalKey() { | 
| 502   pthread_key_t key; | 511   pthread_key_t key; | 
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 619 | 628 | 
| 620  private: | 629  private: | 
| 621   // Note: for profiled_thread_ Mach primitives are used instead of PThread's | 630   // Note: for profiled_thread_ Mach primitives are used instead of PThread's | 
| 622   // because the latter doesn't provide thread manipulation primitives required. | 631   // because the latter doesn't provide thread manipulation primitives required. | 
| 623   // For details, consult "Mac OS X Internals" book, Section 7.3. | 632   // For details, consult "Mac OS X Internals" book, Section 7.3. | 
| 624   thread_act_t profiled_thread_; | 633   thread_act_t profiled_thread_; | 
| 625 }; | 634 }; | 
| 626 | 635 | 
| 627 class SamplerThread : public Thread { | 636 class SamplerThread : public Thread { | 
| 628  public: | 637  public: | 
| 629   explicit SamplerThread(int interval) : Thread(NULL), interval_(interval) {} | 638   explicit SamplerThread(int interval) | 
|  | 639       : Thread(NULL, "SamplerThread"), | 
|  | 640         interval_(interval) {} | 
| 630 | 641 | 
| 631   static void AddActiveSampler(Sampler* sampler) { | 642   static void AddActiveSampler(Sampler* sampler) { | 
| 632     ScopedLock lock(mutex_); | 643     ScopedLock lock(mutex_); | 
| 633     SamplerRegistry::AddActiveSampler(sampler); | 644     SamplerRegistry::AddActiveSampler(sampler); | 
| 634     if (instance_ == NULL) { | 645     if (instance_ == NULL) { | 
| 635       instance_ = new SamplerThread(sampler->interval()); | 646       instance_ = new SamplerThread(sampler->interval()); | 
| 636       instance_->Start(); | 647       instance_->Start(); | 
| 637     } else { | 648     } else { | 
| 638       ASSERT(instance_->interval_ == sampler->interval()); | 649       ASSERT(instance_->interval_ == sampler->interval()); | 
| 639     } | 650     } | 
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 776 | 787 | 
| 777 void Sampler::Stop() { | 788 void Sampler::Stop() { | 
| 778   ASSERT(IsActive()); | 789   ASSERT(IsActive()); | 
| 779   SamplerThread::RemoveActiveSampler(this); | 790   SamplerThread::RemoveActiveSampler(this); | 
| 780   SetActive(false); | 791   SetActive(false); | 
| 781 } | 792 } | 
| 782 | 793 | 
| 783 #endif  // ENABLE_LOGGING_AND_PROFILING | 794 #endif  // ENABLE_LOGGING_AND_PROFILING | 
| 784 | 795 | 
| 785 } }  // namespace v8::internal | 796 } }  // namespace v8::internal | 
| OLD | NEW | 
|---|