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

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

Issue 9455088: Remove static initializers in v8. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address Florian's comments. Created 8 years, 9 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-openbsd.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 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 739
740 class SamplerThread : public Thread { 740 class SamplerThread : public Thread {
741 public: 741 public:
742 static const int kSamplerThreadStackSize = 64 * KB; 742 static const int kSamplerThreadStackSize = 64 * KB;
743 743
744 explicit SamplerThread(int interval) 744 explicit SamplerThread(int interval)
745 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), 745 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)),
746 interval_(interval) {} 746 interval_(interval) {}
747 747
748 static void AddActiveSampler(Sampler* sampler) { 748 static void AddActiveSampler(Sampler* sampler) {
749 ScopedLock lock(mutex_); 749 ScopedLock lock(mutex_.Pointer());
750 SamplerRegistry::AddActiveSampler(sampler); 750 SamplerRegistry::AddActiveSampler(sampler);
751 if (instance_ == NULL) { 751 if (instance_ == NULL) {
752 instance_ = new SamplerThread(sampler->interval()); 752 instance_ = new SamplerThread(sampler->interval());
753 instance_->Start(); 753 instance_->Start();
754 } else { 754 } else {
755 ASSERT(instance_->interval_ == sampler->interval()); 755 ASSERT(instance_->interval_ == sampler->interval());
756 } 756 }
757 } 757 }
758 758
759 static void RemoveActiveSampler(Sampler* sampler) { 759 static void RemoveActiveSampler(Sampler* sampler) {
760 ScopedLock lock(mutex_); 760 ScopedLock lock(mutex_.Pointer());
761 SamplerRegistry::RemoveActiveSampler(sampler); 761 SamplerRegistry::RemoveActiveSampler(sampler);
762 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { 762 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
763 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); 763 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
764 delete instance_; 764 delete instance_;
765 instance_ = NULL; 765 instance_ = NULL;
766 } 766 }
767 } 767 }
768 768
769 // Implement Thread::Run(). 769 // Implement Thread::Run().
770 virtual void Run() { 770 virtual void Run() {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 sampler->SampleStack(sample); 847 sampler->SampleStack(sample);
848 sampler->Tick(sample); 848 sampler->Tick(sample);
849 } 849 }
850 thread_resume(profiled_thread); 850 thread_resume(profiled_thread);
851 } 851 }
852 852
853 const int interval_; 853 const int interval_;
854 RuntimeProfilerRateLimiter rate_limiter_; 854 RuntimeProfilerRateLimiter rate_limiter_;
855 855
856 // Protects the process wide state below. 856 // Protects the process wide state below.
857 static Mutex* mutex_; 857 static LazyMutex mutex_;
858 static SamplerThread* instance_; 858 static SamplerThread* instance_;
859 859
860 private: 860 private:
861 DISALLOW_COPY_AND_ASSIGN(SamplerThread); 861 DISALLOW_COPY_AND_ASSIGN(SamplerThread);
862 }; 862 };
863 863
864 #undef REGISTER_FIELD 864 #undef REGISTER_FIELD
865 865
866 866
867 Mutex* SamplerThread::mutex_ = OS::CreateMutex(); 867 LazyMutex SamplerThread::mutex_ = LAZY_MUTEX_INITIALIZER;
868 SamplerThread* SamplerThread::instance_ = NULL; 868 SamplerThread* SamplerThread::instance_ = NULL;
869 869
870 870
871 Sampler::Sampler(Isolate* isolate, int interval) 871 Sampler::Sampler(Isolate* isolate, int interval)
872 : isolate_(isolate), 872 : isolate_(isolate),
873 interval_(interval), 873 interval_(interval),
874 profiling_(false), 874 profiling_(false),
875 active_(false), 875 active_(false),
876 samples_taken_(0) { 876 samples_taken_(0) {
877 data_ = new PlatformData; 877 data_ = new PlatformData;
(...skipping 14 matching lines...) Expand all
892 892
893 893
894 void Sampler::Stop() { 894 void Sampler::Stop() {
895 ASSERT(IsActive()); 895 ASSERT(IsActive());
896 SamplerThread::RemoveActiveSampler(this); 896 SamplerThread::RemoveActiveSampler(this);
897 SetActive(false); 897 SetActive(false);
898 } 898 }
899 899
900 900
901 } } // namespace v8::internal 901 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-openbsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698