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

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

Issue 9976003: Minimize uses of lazy initialization by adding explicit initialization functions. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address Daniel's comments. Created 8 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/log.cc ('k') | src/platform-freebsd.cc » ('j') | src/v8.cc » ('J')
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 56
57 double ceiling(double x) { 57 double ceiling(double x) {
58 return ceil(x); 58 return ceil(x);
59 } 59 }
60 60
61 61
62 static Mutex* limit_mutex = NULL; 62 static Mutex* limit_mutex = NULL;
63 63
64 64
65 void OS::SetUp() {
66 // Seed the random number generator.
67 // Convert the current time to a 64-bit integer first, before converting it
68 // to an unsigned. Going directly can cause an overflow and the seed to be
69 // set to all ones. The seed will be identical for different instances that
70 // call this setup code within the same millisecond.
71 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
72 srandom(static_cast<unsigned int>(seed));
73 limit_mutex = CreateMutex();
74 }
75
76
77 void OS::PostSetUp() { 65 void OS::PostSetUp() {
78 // Math functions depend on CPU features therefore they are initialized after 66 POSIXPostSetUp();
79 // CPU.
80 MathSetup();
81 } 67 }
82 68
83 uint64_t OS::CpuFeaturesImpliedByPlatform() { 69 uint64_t OS::CpuFeaturesImpliedByPlatform() {
84 return 0; // Nothing special about Cygwin. 70 return 0; // Nothing special about Cygwin.
85 } 71 }
86 72
87 73
88 int OS::ActivationFrameAlignment() { 74 int OS::ActivationFrameAlignment() {
89 // With gcc 4.4 the tree vectorization optimizer can generate code 75 // With gcc 4.4 the tree vectorization optimizer can generate code
90 // that requires 16 byte alignment such as movdqa on x86. 76 // that requires 16 byte alignment such as movdqa on x86.
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 613
628 614
629 class SamplerThread : public Thread { 615 class SamplerThread : public Thread {
630 public: 616 public:
631 static const int kSamplerThreadStackSize = 64 * KB; 617 static const int kSamplerThreadStackSize = 64 * KB;
632 618
633 explicit SamplerThread(int interval) 619 explicit SamplerThread(int interval)
634 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), 620 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)),
635 interval_(interval) {} 621 interval_(interval) {}
636 622
623 static void SetUp() {
624 if (!mutex_) {
625 mutex_ = OS::CreateMutex();
626 }
627 }
628
637 static void AddActiveSampler(Sampler* sampler) { 629 static void AddActiveSampler(Sampler* sampler) {
638 ScopedLock lock(mutex_.Pointer()); 630 ScopedLock lock(mutex_);
639 SamplerRegistry::AddActiveSampler(sampler); 631 SamplerRegistry::AddActiveSampler(sampler);
640 if (instance_ == NULL) { 632 if (instance_ == NULL) {
641 instance_ = new SamplerThread(sampler->interval()); 633 instance_ = new SamplerThread(sampler->interval());
642 instance_->Start(); 634 instance_->Start();
643 } else { 635 } else {
644 ASSERT(instance_->interval_ == sampler->interval()); 636 ASSERT(instance_->interval_ == sampler->interval());
645 } 637 }
646 } 638 }
647 639
648 static void RemoveActiveSampler(Sampler* sampler) { 640 static void RemoveActiveSampler(Sampler* sampler) {
649 ScopedLock lock(mutex_.Pointer()); 641 ScopedLock lock(mutex_);
650 SamplerRegistry::RemoveActiveSampler(sampler); 642 SamplerRegistry::RemoveActiveSampler(sampler);
651 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { 643 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
652 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); 644 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_);
653 delete instance_; 645 delete instance_;
654 instance_ = NULL; 646 instance_ = NULL;
655 } 647 }
656 } 648 }
657 649
658 // Implement Thread::Run(). 650 // Implement Thread::Run().
659 virtual void Run() { 651 virtual void Run() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 sampler->SampleStack(sample); 717 sampler->SampleStack(sample);
726 sampler->Tick(sample); 718 sampler->Tick(sample);
727 } 719 }
728 ResumeThread(profiled_thread); 720 ResumeThread(profiled_thread);
729 } 721 }
730 722
731 const int interval_; 723 const int interval_;
732 RuntimeProfilerRateLimiter rate_limiter_; 724 RuntimeProfilerRateLimiter rate_limiter_;
733 725
734 // Protects the process wide state below. 726 // Protects the process wide state below.
735 static LazyMutex mutex_; 727 static Mutex* mutex_;
736 static SamplerThread* instance_; 728 static SamplerThread* instance_;
737 729
738 private: 730 private:
739 DISALLOW_COPY_AND_ASSIGN(SamplerThread); 731 DISALLOW_COPY_AND_ASSIGN(SamplerThread);
740 }; 732 };
741 733
742 734
743 LazyMutex SamplerThread::mutex_ = LAZY_MUTEX_INITIALIZER; 735 Mutex* SamplerThread::mutex_ = NULL;
744 SamplerThread* SamplerThread::instance_ = NULL; 736 SamplerThread* SamplerThread::instance_ = NULL;
745 737
746 738
739 void OS::SetUp() {
740 // Seed the random number generator.
741 // Convert the current time to a 64-bit integer first, before converting it
742 // to an unsigned. Going directly can cause an overflow and the seed to be
743 // set to all ones. The seed will be identical for different instances that
744 // call this setup code within the same millisecond.
745 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
746 srandom(static_cast<unsigned int>(seed));
747 limit_mutex = CreateMutex();
748 SamplerThread::SetUp();
749 }
750
751
747 Sampler::Sampler(Isolate* isolate, int interval) 752 Sampler::Sampler(Isolate* isolate, int interval)
748 : isolate_(isolate), 753 : isolate_(isolate),
749 interval_(interval), 754 interval_(interval),
750 profiling_(false), 755 profiling_(false),
751 active_(false), 756 active_(false),
752 samples_taken_(0) { 757 samples_taken_(0) {
753 data_ = new PlatformData; 758 data_ = new PlatformData;
754 } 759 }
755 760
756 761
(...skipping 11 matching lines...) Expand all
768 773
769 774
770 void Sampler::Stop() { 775 void Sampler::Stop() {
771 ASSERT(IsActive()); 776 ASSERT(IsActive());
772 SamplerThread::RemoveActiveSampler(this); 777 SamplerThread::RemoveActiveSampler(this);
773 SetActive(false); 778 SetActive(false);
774 } 779 }
775 780
776 781
777 } } // namespace v8::internal 782 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/log.cc ('k') | src/platform-freebsd.cc » ('j') | src/v8.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698