2010-05-22 05:27:19 +00:00
|
|
|
// Copyright 2010 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2010-05-22 05:27:19 +00:00
|
|
|
|
|
|
|
#ifndef V8_UNBOUND_QUEUE_
|
|
|
|
#define V8_UNBOUND_QUEUE_
|
|
|
|
|
2011-05-06 06:50:20 +00:00
|
|
|
#include "allocation.h"
|
|
|
|
|
2010-05-22 05:27:19 +00:00
|
|
|
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();
|
|
|
|
|
2013-06-20 06:23:34 +00:00
|
|
|
INLINE(bool Dequeue(Record* rec));
|
2010-05-22 05:27:19 +00:00
|
|
|
INLINE(void Enqueue(const Record& rec));
|
2013-06-20 06:23:34 +00:00
|
|
|
INLINE(bool IsEmpty() const);
|
|
|
|
INLINE(Record* Peek() const);
|
2010-05-22 05:27:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
INLINE(void DeleteFirst());
|
|
|
|
|
|
|
|
struct Node;
|
|
|
|
|
|
|
|
Node* first_;
|
|
|
|
AtomicWord divider_; // Node*
|
|
|
|
AtomicWord last_; // Node*
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(UnboundQueue);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_UNBOUND_QUEUE_
|