Revision: 24465
Author:   [email protected]
Date:     Wed Oct  8 11:33:31 2014 UTC
Log:      Make Profiler::tail_ atomic

it's used on several threads

BUG=none
[email protected]
LOG=n

Review URL: https://codereview.chromium.org/639763002
https://code.google.com/p/v8/source/detail?r=24465

Modified:
 /branches/bleeding_edge/src/log.cc

=======================================
--- /branches/bleeding_edge/src/log.cc  Tue Sep 30 10:29:32 2014 UTC
+++ /branches/bleeding_edge/src/log.cc  Wed Oct  8 11:33:31 2014 UTC
@@ -607,7 +607,7 @@
     if (paused_)
       return;

-    if (Succ(head_) == tail_) {
+    if (Succ(head_) == static_cast<int>(base::NoBarrier_Load(&tail_))) {
       overflow_ = true;
     } else {
       buffer_[head_] = *sample;
@@ -626,9 +626,10 @@
   // Waits for a signal and removes profiling data.
   bool Remove(TickSample* sample) {
     buffer_semaphore_.Wait();  // Wait for an element.
-    *sample = buffer_[tail_];
+    *sample = buffer_[base::NoBarrier_Load(&tail_)];
     bool result = overflow_;
-    tail_ = Succ(tail_);
+    base::NoBarrier_Store(&tail_, static_cast<base::Atomic32>(
+                                      Succ(base::NoBarrier_Load(&tail_))));
     overflow_ = false;
     return result;
   }
@@ -642,7 +643,7 @@
   static const int kBufferSize = 128;
   TickSample buffer_[kBufferSize];  // Buffer storage.
   int head_;  // Index to the buffer head.
-  int tail_;  // Index to the buffer tail.
+  base::Atomic32 tail_;             // Index to the buffer tail.
   bool overflow_;  // Tell whether a buffer overflow has occurred.
   // Sempahore used for buffer synchronization.
   base::Semaphore buffer_semaphore_;
@@ -699,12 +700,13 @@
     : base::Thread(Options("v8:Profiler")),
       isolate_(isolate),
       head_(0),
-      tail_(0),
       overflow_(false),
       buffer_semaphore_(0),
       engaged_(false),
       running_(false),
-      paused_(false) {}
+      paused_(false) {
+  base::NoBarrier_Store(&tail_, 0);
+}


 void Profiler::Engage() {

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to