• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/base/platform/platform.h"
9 #include "src/utils/allocation.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 // Simple lock-based unbounded size queue (multi producer; multi consumer) based
15 // on "Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue
16 // Algorithms" by M. Scott and M. Michael.
17 // See:
18 // https://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html
19 template <typename Record>
20 class LockedQueue final {
21  public:
22   inline LockedQueue();
23   inline ~LockedQueue();
24   inline void Enqueue(Record record);
25   inline bool Dequeue(Record* record);
26   inline bool IsEmpty() const;
27   inline bool Peek(Record* record) const;
28 
29  private:
30   struct Node;
31 
32   mutable base::Mutex head_mutex_;
33   base::Mutex tail_mutex_;
34   Node* head_;
35   Node* tail_;
36 
37   DISALLOW_COPY_AND_ASSIGN(LockedQueue);
38 };
39 
40 }  // namespace internal
41 }  // namespace v8
42 
43 #endif  // V8_UTILS_LOCKED_QUEUE_H_
44