circular-queue-inl.h 1.65 KB
Newer Older
1
// Copyright 2011 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_PROFILER_CIRCULAR_QUEUE_INL_H_
#define V8_PROFILER_CIRCULAR_QUEUE_INL_H_
7

8
#include "src/profiler/circular-queue.h"
9 10 11 12

namespace v8 {
namespace internal {

13 14 15 16 17 18 19 20 21 22 23 24 25
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>
26
T* SamplingCircularQueue<T, L>::Peek() {
27
  base::SeqCst_MemoryFence();
28
  if (base::Acquire_Load(&dequeue_pos_->marker) == kFull) {
29 30 31 32 33 34 35
    return &dequeue_pos_->record;
  }
  return NULL;
}


template<typename T, unsigned L>
36
void SamplingCircularQueue<T, L>::Remove() {
37
  base::Release_Store(&dequeue_pos_->marker, kEmpty);
38 39
  dequeue_pos_ = Next(dequeue_pos_);
}
40

41 42 43

template<typename T, unsigned L>
T* SamplingCircularQueue<T, L>::StartEnqueue() {
44
  base::SeqCst_MemoryFence();
45
  if (base::Acquire_Load(&enqueue_pos_->marker) == kEmpty) {
46
    return &enqueue_pos_->record;
47
  }
48
  return NULL;
49 50 51
}


52 53
template<typename T, unsigned L>
void SamplingCircularQueue<T, L>::FinishEnqueue() {
54
  base::Release_Store(&enqueue_pos_->marker, kFull);
55
  enqueue_pos_ = Next(enqueue_pos_);
56 57 58
}


59 60 61 62 63 64 65 66
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;
}

67 68
}  // namespace internal
}  // namespace v8
69

70
#endif  // V8_PROFILER_CIRCULAR_QUEUE_INL_H_