1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_PROFILER_CIRCULAR_QUEUE_INL_H_
6 #define V8_PROFILER_CIRCULAR_QUEUE_INL_H_
7
8 #include "src/profiler/circular-queue.h"
9
10 namespace v8 {
11 namespace internal {
12
13 template<typename T, unsigned L>
SamplingCircularQueue()14 SamplingCircularQueue<T, L>::SamplingCircularQueue()
15 : enqueue_pos_(buffer_),
16 dequeue_pos_(buffer_) {
17 }
18
19 template <typename T, unsigned L>
20 SamplingCircularQueue<T, L>::~SamplingCircularQueue() = default;
21
22 template<typename T, unsigned L>
Peek()23 T* SamplingCircularQueue<T, L>::Peek() {
24 base::SeqCst_MemoryFence();
25 if (base::Acquire_Load(&dequeue_pos_->marker) == kFull) {
26 return &dequeue_pos_->record;
27 }
28 return nullptr;
29 }
30
31
32 template<typename T, unsigned L>
Remove()33 void SamplingCircularQueue<T, L>::Remove() {
34 base::Release_Store(&dequeue_pos_->marker, kEmpty);
35 dequeue_pos_ = Next(dequeue_pos_);
36 }
37
38
39 template<typename T, unsigned L>
StartEnqueue()40 T* SamplingCircularQueue<T, L>::StartEnqueue() {
41 base::SeqCst_MemoryFence();
42 if (base::Acquire_Load(&enqueue_pos_->marker) == kEmpty) {
43 return &enqueue_pos_->record;
44 }
45 return nullptr;
46 }
47
48
49 template<typename T, unsigned L>
FinishEnqueue()50 void SamplingCircularQueue<T, L>::FinishEnqueue() {
51 base::Release_Store(&enqueue_pos_->marker, kFull);
52 enqueue_pos_ = Next(enqueue_pos_);
53 }
54
55
56 template<typename T, unsigned L>
Next(Entry * entry)57 typename SamplingCircularQueue<T, L>::Entry* SamplingCircularQueue<T, L>::Next(
58 Entry* entry) {
59 Entry* next = entry + 1;
60 if (next == &buffer_[L]) return buffer_;
61 return next;
62 }
63
64 } // namespace internal
65 } // namespace v8
66
67 #endif // V8_PROFILER_CIRCULAR_QUEUE_INL_H_
68