799fc835f8
BUG=none R=jkummerow@chromium.org LOG=n Review URL: https://codereview.chromium.org/316133002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21693 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
// Copyright 2010 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef V8_UNBOUND_QUEUE_
|
|
#define V8_UNBOUND_QUEUE_
|
|
|
|
#include "src/allocation.h"
|
|
#include "src/base/atomicops.h"
|
|
|
|
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();
|
|
|
|
INLINE(bool Dequeue(Record* rec));
|
|
INLINE(void Enqueue(const Record& rec));
|
|
INLINE(bool IsEmpty() const);
|
|
INLINE(Record* Peek() const);
|
|
|
|
private:
|
|
INLINE(void DeleteFirst());
|
|
|
|
struct Node;
|
|
|
|
Node* first_;
|
|
base::AtomicWord divider_; // Node*
|
|
base::AtomicWord last_; // Node*
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(UnboundQueue);
|
|
};
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
#endif // V8_UNBOUND_QUEUE_
|