Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: src/platform-macos.cc

Issue 13627002: Add sanity test for CPU profiler (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Start sampler and processor threads synchronously Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-nullos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 488
489 class Thread::PlatformData : public Malloced { 489 class Thread::PlatformData : public Malloced {
490 public: 490 public:
491 PlatformData() : thread_(kNoThread) {} 491 PlatformData() : thread_(kNoThread) {}
492 pthread_t thread_; // Thread handle for pthread. 492 pthread_t thread_; // Thread handle for pthread.
493 }; 493 };
494 494
495 495
496 Thread::Thread(const Options& options) 496 Thread::Thread(const Options& options)
497 : data_(new PlatformData), 497 : data_(new PlatformData),
498 stack_size_(options.stack_size()) { 498 stack_size_(options.stack_size()),
499 start_semaphore_(NULL) {
499 set_name(options.name()); 500 set_name(options.name());
500 } 501 }
501 502
502 503
503 Thread::~Thread() { 504 Thread::~Thread() {
504 delete data_; 505 delete data_;
505 } 506 }
506 507
507 508
508 static void SetThreadName(const char* name) { 509 static void SetThreadName(const char* name) {
(...skipping 14 matching lines...) Expand all
523 524
524 525
525 static void* ThreadEntry(void* arg) { 526 static void* ThreadEntry(void* arg) {
526 Thread* thread = reinterpret_cast<Thread*>(arg); 527 Thread* thread = reinterpret_cast<Thread*>(arg);
527 // This is also initialized by the first argument to pthread_create() but we 528 // This is also initialized by the first argument to pthread_create() but we
528 // don't know which thread will run first (the original thread or the new 529 // don't know which thread will run first (the original thread or the new
529 // one) so we initialize it here too. 530 // one) so we initialize it here too.
530 thread->data()->thread_ = pthread_self(); 531 thread->data()->thread_ = pthread_self();
531 SetThreadName(thread->name()); 532 SetThreadName(thread->name());
532 ASSERT(thread->data()->thread_ != kNoThread); 533 ASSERT(thread->data()->thread_ != kNoThread);
533 thread->Run(); 534 thread->NotifyStartedAndRun();
534 return NULL; 535 return NULL;
535 } 536 }
536 537
537 538
538 void Thread::set_name(const char* name) { 539 void Thread::set_name(const char* name) {
539 strncpy(name_, name, sizeof(name_)); 540 strncpy(name_, name, sizeof(name_));
540 name_[sizeof(name_) - 1] = '\0'; 541 name_[sizeof(name_) - 1] = '\0';
541 } 542 }
542 543
543 544
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 interval_(interval) {} 770 interval_(interval) {}
770 771
771 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } 772 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); }
772 static void TearDown() { delete mutex_; } 773 static void TearDown() { delete mutex_; }
773 774
774 static void AddActiveSampler(Sampler* sampler) { 775 static void AddActiveSampler(Sampler* sampler) {
775 ScopedLock lock(mutex_); 776 ScopedLock lock(mutex_);
776 SamplerRegistry::AddActiveSampler(sampler); 777 SamplerRegistry::AddActiveSampler(sampler);
777 if (instance_ == NULL) { 778 if (instance_ == NULL) {
778 instance_ = new SamplerThread(sampler->interval()); 779 instance_ = new SamplerThread(sampler->interval());
779 instance_->Start(); 780 instance_->StartSynchronously();
780 } else { 781 } else {
781 ASSERT(instance_->interval_ == sampler->interval()); 782 ASSERT(instance_->interval_ == sampler->interval());
782 } 783 }
783 } 784 }
784 785
785 static void RemoveActiveSampler(Sampler* sampler) { 786 static void RemoveActiveSampler(Sampler* sampler) {
786 ScopedLock lock(mutex_); 787 ScopedLock lock(mutex_);
787 SamplerRegistry::RemoveActiveSampler(sampler); 788 SamplerRegistry::RemoveActiveSampler(sampler);
788 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { 789 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
789 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); 790 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 918
918 919
919 void Sampler::Stop() { 920 void Sampler::Stop() {
920 ASSERT(IsActive()); 921 ASSERT(IsActive());
921 SamplerThread::RemoveActiveSampler(this); 922 SamplerThread::RemoveActiveSampler(this);
922 SetActive(false); 923 SetActive(false);
923 } 924 }
924 925
925 926
926 } } // namespace v8::internal 927 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-nullos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698