v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
locked-queue-inl.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_INL_H_
6#define V8_UTILS_LOCKED_QUEUE_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
13
14namespace v8 {
15namespace internal {
16
17template <typename Record>
18struct LockedQueue<Record>::Node : Malloced {
19 Node() : next(nullptr) {}
20 Record value;
22};
23
24template <typename Record>
26 head_ = new Node();
28 tail_ = head_;
29 size_ = 0;
32template <typename Record>
34 // Destroy all remaining nodes. Note that we do not destroy the actual values.
35 Node* old_node = nullptr;
36 Node* cur_node = head_;
37 while (cur_node != nullptr) {
38 old_node = cur_node;
39 cur_node = cur_node->next.Value();
40 delete old_node;
41 }
42}
43
44template <typename Record>
46 Node* n = new Node();
48 n->value = std::move(record);
49 {
50 base::MutexGuard guard(&tail_mutex_);
51 size_++;
52 tail_->next.SetValue(n);
53 tail_ = n;
54 }
55}
56
57template <typename Record>
59 Node* old_head = nullptr;
60 {
61 base::MutexGuard guard(&head_mutex_);
62 old_head = head_;
63 Node* const next_node = head_->next.Value();
64 if (next_node == nullptr) return false;
65 *record = std::move(next_node->value);
66 head_ = next_node;
67 size_t old_size = size_.fetch_sub(1);
68 USE(old_size);
69 DCHECK_GT(old_size, 0);
70 }
71 delete old_head;
72 return true;
73}
74
75template <typename Record>
76inline bool LockedQueue<Record>::IsEmpty() const {
77 base::MutexGuard guard(&head_mutex_);
78 return head_->next.Value() == nullptr;
79}
80
81template <typename Record>
82inline bool LockedQueue<Record>::Peek(Record* record) const {
83 base::MutexGuard guard(&head_mutex_);
84 Node* const next_node = head_->next.Value();
85 if (next_node == nullptr) return false;
86 *record = next_node->value;
87 return true;
88}
89
90template <typename Record>
91inline size_t LockedQueue<Record>::size() const {
92 return size_;
93}
94
95} // namespace internal
96} // namespace v8
97
98#endif // V8_UTILS_LOCKED_QUEUE_INL_H_
bool Peek(Record *record) const
void Enqueue(Record record)
bool Dequeue(Record *record)
const int size_
Definition assembler.cc:132
DurationRecord record
int n
Definition mul-fft.cc:296
#define CHECK_NOT_NULL(val)
#define DCHECK_GT(v1, v2)
Definition logging.h:487
#define USE(...)
Definition macros.h:293
base::AtomicValue< Node * > next