// Copyright 2011 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_PROFILER_CIRCULAR_QUEUE_INL_H_ #define V8_PROFILER_CIRCULAR_QUEUE_INL_H_ #include "src/profiler/circular-queue.h" namespace v8 { namespace internal { template SamplingCircularQueue::SamplingCircularQueue() : enqueue_pos_(buffer_), dequeue_pos_(buffer_) { } template SamplingCircularQueue::~SamplingCircularQueue() = default; template T* SamplingCircularQueue::Peek() { base::SeqCst_MemoryFence(); if (base::Acquire_Load(&dequeue_pos_->marker) == kFull) { return &dequeue_pos_->record; } return nullptr; } template void SamplingCircularQueue::Remove() { base::Release_Store(&dequeue_pos_->marker, kEmpty); dequeue_pos_ = Next(dequeue_pos_); } template T* SamplingCircularQueue::StartEnqueue() { base::SeqCst_MemoryFence(); if (base::Acquire_Load(&enqueue_pos_->marker) == kEmpty) { return &enqueue_pos_->record; } return nullptr; } template void SamplingCircularQueue::FinishEnqueue() { base::Release_Store(&enqueue_pos_->marker, kFull); enqueue_pos_ = Next(enqueue_pos_); } template typename SamplingCircularQueue::Entry* SamplingCircularQueue::Next( Entry* entry) { Entry* next = entry + 1; if (next == &buffer_[L]) return buffer_; return next; } } // namespace internal } // namespace v8 #endif // V8_PROFILER_CIRCULAR_QUEUE_INL_H_