v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
locked-queue.h
Go to the documentation of this file.
1// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_UTILS_LOCKED_QUEUE_H_
6#define V8_UTILS_LOCKED_QUEUE_H_
7
8#include <atomic>
9
12
13namespace v8 {
14namespace internal {
15
16// Simple lock-based unbounded size queue (multi producer; multi consumer) based
17// on "Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue
18// Algorithms" by M. Scott and M. Michael.
19// See:
20// https://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html
21template <typename Record>
22class LockedQueue final {
23 public:
24 inline LockedQueue();
25 LockedQueue(const LockedQueue&) = delete;
27 inline ~LockedQueue();
28 inline void Enqueue(Record record);
29 inline bool Dequeue(Record* record);
30 inline bool IsEmpty() const;
31 inline bool Peek(Record* record) const;
32 inline size_t size() const;
33
34 private:
35 struct Node;
36
41 std::atomic<size_t> size_;
42};
43
44} // namespace internal
45} // namespace v8
46
47#endif // V8_UTILS_LOCKED_QUEUE_H_
bool Peek(Record *record) const
std::atomic< size_t > size_
LockedQueue(const LockedQueue &)=delete
LockedQueue & operator=(const LockedQueue &)=delete
void Enqueue(Record record)
bool Dequeue(Record *record)
DurationRecord record