unbound-queue.h 1.19 KB
Newer Older
1
// Copyright 2010 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_UNBOUND_QUEUE_
#define V8_PROFILER_UNBOUND_QUEUE_
7

8
#include "src/allocation.h"
9
#include "src/base/atomicops.h"
10

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
namespace v8 {
namespace internal {


// Lock-free unbound queue for small records.  Intended for
// transferring small records between a Single producer and a Single
// consumer. Doesn't have restrictions on the number of queued
// elements, so producer never blocks.  Implemented after Herb
// Sutter's article:
// http://www.ddj.com/high-performance-computing/210604448
template<typename Record>
class UnboundQueue BASE_EMBEDDED {
 public:
  inline UnboundQueue();
  inline ~UnboundQueue();

27
  INLINE(bool Dequeue(Record* rec));
28
  INLINE(void Enqueue(const Record& rec));
29 30
  INLINE(bool IsEmpty() const);
  INLINE(Record* Peek() const);
31 32 33 34 35 36 37

 private:
  INLINE(void DeleteFirst());

  struct Node;

  Node* first_;
38 39
  base::AtomicWord divider_;  // Node*
  base::AtomicWord last_;     // Node*
40 41 42 43 44

  DISALLOW_COPY_AND_ASSIGN(UnboundQueue);
};


45 46
}  // namespace internal
}  // namespace v8
47

48
#endif  // V8_PROFILER_UNBOUND_QUEUE_