Index: src/circular-queue-inl.h |
diff --git a/src/circular-queue-inl.h b/src/circular-queue-inl.h |
index b48070ab5d24a064e4f8a91a72020e80d8f02954..8b09eeb9fb46c4462fb2472c44d662eeff0bf5a2 100644 |
--- a/src/circular-queue-inl.h |
+++ b/src/circular-queue-inl.h |
@@ -33,30 +33,60 @@ |
namespace v8 { |
namespace internal { |
+template<typename T, unsigned L> |
+SamplingCircularQueue<T, L>::SamplingCircularQueue() |
+ : enqueue_pos_(buffer_), |
+ dequeue_pos_(buffer_) { |
+} |
+ |
+ |
+template<typename T, unsigned L> |
+SamplingCircularQueue<T, L>::~SamplingCircularQueue() { |
+} |
+ |
+ |
+template<typename T, unsigned L> |
+T* SamplingCircularQueue<T, L>::StartDequeue() { |
+ MemoryBarrier(); |
+ if (Acquire_Load(&dequeue_pos_->marker) == kFull) { |
+ return &dequeue_pos_->record; |
+ } |
+ return NULL; |
+} |
+ |
+ |
+template<typename T, unsigned L> |
+void SamplingCircularQueue<T, L>::FinishDequeue() { |
+ Release_Store(&dequeue_pos_->marker, kEmpty); |
+ dequeue_pos_ = Next(dequeue_pos_); |
+} |
-void* SamplingCircularQueue::Enqueue() { |
- if (producer_pos_->enqueue_pos == producer_pos_->next_chunk_pos) { |
- if (producer_pos_->enqueue_pos == buffer_ + buffer_size_) { |
- producer_pos_->next_chunk_pos = buffer_; |
- producer_pos_->enqueue_pos = buffer_; |
- } |
- Acquire_Store(producer_pos_->next_chunk_pos, kEnqueueStarted); |
- // Skip marker. |
- producer_pos_->enqueue_pos += 1; |
- producer_pos_->next_chunk_pos += chunk_size_; |
+ |
+template<typename T, unsigned L> |
+T* SamplingCircularQueue<T, L>::StartEnqueue() { |
+ MemoryBarrier(); |
+ if (Acquire_Load(&enqueue_pos_->marker) == kEmpty) { |
+ return &enqueue_pos_->record; |
} |
- void* result = producer_pos_->enqueue_pos; |
- producer_pos_->enqueue_pos += record_size_; |
- return result; |
+ return NULL; |
} |
-void SamplingCircularQueue::WrapPositionIfNeeded( |
- SamplingCircularQueue::Cell** pos) { |
- if (*pos == buffer_ + buffer_size_) *pos = buffer_; |
+template<typename T, unsigned L> |
+void SamplingCircularQueue<T, L>::FinishEnqueue() { |
+ Release_Store(&enqueue_pos_->marker, kFull); |
+ enqueue_pos_ = Next(enqueue_pos_); |
} |
+template<typename T, unsigned L> |
+typename SamplingCircularQueue<T, L>::Entry* SamplingCircularQueue<T, L>::Next( |
+ Entry* entry) { |
+ Entry* next = entry + 1; |
+ if (next == &buffer_[L]) return buffer_; |
+ return next; |
+} |
+ |
} } // namespace v8::internal |
#endif // V8_CIRCULAR_QUEUE_INL_H_ |