183e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org// Copyright 2011 the V8 project authors. All rights reserved.
23484964a86451e86dcf04be9bd8c0d76ee04f081rossberg@chromium.org// Use of this source code is governed by a BSD-style license that can be
33484964a86451e86dcf04be9bd8c0d76ee04f081rossberg@chromium.org// found in the LICENSE file.
4cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.org
583e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org#ifndef V8_CIRCULAR_QUEUE_INL_H_
683e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org#define V8_CIRCULAR_QUEUE_INL_H_
7cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.org
8196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/circular-queue.h"
9cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.org
10cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.orgnamespace v8 {
11cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.orgnamespace internal {
12cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.org
139259716434187c932704601f700375e53d865de8rossberg@chromium.orgtemplate<typename T, unsigned L>
149259716434187c932704601f700375e53d865de8rossberg@chromium.orgSamplingCircularQueue<T, L>::SamplingCircularQueue()
159259716434187c932704601f700375e53d865de8rossberg@chromium.org    : enqueue_pos_(buffer_),
169259716434187c932704601f700375e53d865de8rossberg@chromium.org      dequeue_pos_(buffer_) {
179259716434187c932704601f700375e53d865de8rossberg@chromium.org}
189259716434187c932704601f700375e53d865de8rossberg@chromium.org
199259716434187c932704601f700375e53d865de8rossberg@chromium.org
209259716434187c932704601f700375e53d865de8rossberg@chromium.orgtemplate<typename T, unsigned L>
219259716434187c932704601f700375e53d865de8rossberg@chromium.orgSamplingCircularQueue<T, L>::~SamplingCircularQueue() {
229259716434187c932704601f700375e53d865de8rossberg@chromium.org}
239259716434187c932704601f700375e53d865de8rossberg@chromium.org
249259716434187c932704601f700375e53d865de8rossberg@chromium.org
259259716434187c932704601f700375e53d865de8rossberg@chromium.orgtemplate<typename T, unsigned L>
262c9426bdda5e95459527292063d885c98180cb0fjkummerow@chromium.orgT* SamplingCircularQueue<T, L>::Peek() {
271e2d50cf3d94ff48285da107b7a9da1ad0fc873dmachenbach@chromium.org  base::MemoryBarrier();
281e2d50cf3d94ff48285da107b7a9da1ad0fc873dmachenbach@chromium.org  if (base::Acquire_Load(&dequeue_pos_->marker) == kFull) {
299259716434187c932704601f700375e53d865de8rossberg@chromium.org    return &dequeue_pos_->record;
309259716434187c932704601f700375e53d865de8rossberg@chromium.org  }
319259716434187c932704601f700375e53d865de8rossberg@chromium.org  return NULL;
329259716434187c932704601f700375e53d865de8rossberg@chromium.org}
339259716434187c932704601f700375e53d865de8rossberg@chromium.org
349259716434187c932704601f700375e53d865de8rossberg@chromium.org
359259716434187c932704601f700375e53d865de8rossberg@chromium.orgtemplate<typename T, unsigned L>
362c9426bdda5e95459527292063d885c98180cb0fjkummerow@chromium.orgvoid SamplingCircularQueue<T, L>::Remove() {
371e2d50cf3d94ff48285da107b7a9da1ad0fc873dmachenbach@chromium.org  base::Release_Store(&dequeue_pos_->marker, kEmpty);
389259716434187c932704601f700375e53d865de8rossberg@chromium.org  dequeue_pos_ = Next(dequeue_pos_);
399259716434187c932704601f700375e53d865de8rossberg@chromium.org}
40cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.org
419259716434187c932704601f700375e53d865de8rossberg@chromium.org
429259716434187c932704601f700375e53d865de8rossberg@chromium.orgtemplate<typename T, unsigned L>
439259716434187c932704601f700375e53d865de8rossberg@chromium.orgT* SamplingCircularQueue<T, L>::StartEnqueue() {
441e2d50cf3d94ff48285da107b7a9da1ad0fc873dmachenbach@chromium.org  base::MemoryBarrier();
451e2d50cf3d94ff48285da107b7a9da1ad0fc873dmachenbach@chromium.org  if (base::Acquire_Load(&enqueue_pos_->marker) == kEmpty) {
469259716434187c932704601f700375e53d865de8rossberg@chromium.org    return &enqueue_pos_->record;
47ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  }
489259716434187c932704601f700375e53d865de8rossberg@chromium.org  return NULL;
49cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.org}
50cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.org
51cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.org
529259716434187c932704601f700375e53d865de8rossberg@chromium.orgtemplate<typename T, unsigned L>
539259716434187c932704601f700375e53d865de8rossberg@chromium.orgvoid SamplingCircularQueue<T, L>::FinishEnqueue() {
541e2d50cf3d94ff48285da107b7a9da1ad0fc873dmachenbach@chromium.org  base::Release_Store(&enqueue_pos_->marker, kFull);
559259716434187c932704601f700375e53d865de8rossberg@chromium.org  enqueue_pos_ = Next(enqueue_pos_);
56cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.org}
57cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.org
58cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.org
599259716434187c932704601f700375e53d865de8rossberg@chromium.orgtemplate<typename T, unsigned L>
609259716434187c932704601f700375e53d865de8rossberg@chromium.orgtypename SamplingCircularQueue<T, L>::Entry* SamplingCircularQueue<T, L>::Next(
619259716434187c932704601f700375e53d865de8rossberg@chromium.org    Entry* entry) {
629259716434187c932704601f700375e53d865de8rossberg@chromium.org  Entry* next = entry + 1;
639259716434187c932704601f700375e53d865de8rossberg@chromium.org  if (next == &buffer_[L]) return buffer_;
649259716434187c932704601f700375e53d865de8rossberg@chromium.org  return next;
659259716434187c932704601f700375e53d865de8rossberg@chromium.org}
669259716434187c932704601f700375e53d865de8rossberg@chromium.org
67cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.org} }  // namespace v8::internal
68cec079d8ed1f0920a0ea3dc9a3e81966013287c1whesse@chromium.org
6983e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org#endif  // V8_CIRCULAR_QUEUE_INL_H_
70