blob: 2f06f6c496f2d53656f63e39bf816a269a763d75 [file] [log] [blame]
Ben Murdoch589d6972011-11-30 16:04:58 +00001// Copyright 2011 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Block6ded16b2010-05-10 14:33:55 +01004
Ben Murdoch589d6972011-11-30 16:04:58 +00005#ifndef V8_CIRCULAR_QUEUE_INL_H_
6#define V8_CIRCULAR_QUEUE_INL_H_
Steve Block6ded16b2010-05-10 14:33:55 +01007
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/circular-queue.h"
Steve Block6ded16b2010-05-10 14:33:55 +01009
10namespace v8 {
11namespace internal {
12
Ben Murdochb8a8cc12014-11-26 15:28:44 +000013template<typename T, unsigned L>
14SamplingCircularQueue<T, L>::SamplingCircularQueue()
15 : enqueue_pos_(buffer_),
16 dequeue_pos_(buffer_) {
Steve Block6ded16b2010-05-10 14:33:55 +010017}
18
19
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020template<typename T, unsigned L>
21SamplingCircularQueue<T, L>::~SamplingCircularQueue() {
Steve Block6ded16b2010-05-10 14:33:55 +010022}
23
24
Ben Murdochb8a8cc12014-11-26 15:28:44 +000025template<typename T, unsigned L>
26T* SamplingCircularQueue<T, L>::Peek() {
27 base::MemoryBarrier();
28 if (base::Acquire_Load(&dequeue_pos_->marker) == kFull) {
29 return &dequeue_pos_->record;
30 }
31 return NULL;
32}
33
34
35template<typename T, unsigned L>
36void SamplingCircularQueue<T, L>::Remove() {
37 base::Release_Store(&dequeue_pos_->marker, kEmpty);
38 dequeue_pos_ = Next(dequeue_pos_);
39}
40
41
42template<typename T, unsigned L>
43T* SamplingCircularQueue<T, L>::StartEnqueue() {
44 base::MemoryBarrier();
45 if (base::Acquire_Load(&enqueue_pos_->marker) == kEmpty) {
46 return &enqueue_pos_->record;
47 }
48 return NULL;
49}
50
51
52template<typename T, unsigned L>
53void SamplingCircularQueue<T, L>::FinishEnqueue() {
54 base::Release_Store(&enqueue_pos_->marker, kFull);
55 enqueue_pos_ = Next(enqueue_pos_);
56}
57
58
59template<typename T, unsigned L>
60typename SamplingCircularQueue<T, L>::Entry* SamplingCircularQueue<T, L>::Next(
61 Entry* entry) {
62 Entry* next = entry + 1;
63 if (next == &buffer_[L]) return buffer_;
64 return next;
65}
66
Steve Block6ded16b2010-05-10 14:33:55 +010067} } // namespace v8::internal
68
Ben Murdoch589d6972011-11-30 16:04:58 +000069#endif // V8_CIRCULAR_QUEUE_INL_H_