| // Copyright 2015 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_UTILS_LOCKED_QUEUE_H_ |
| #define V8_UTILS_LOCKED_QUEUE_H_ |
| #include "src/base/platform/platform.h" |
| #include "src/utils/allocation.h" |
| // Simple lock-based unbounded size queue (multi producer; multi consumer) based |
| // on "Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue |
| // Algorithms" by M. Scott and M. Michael. |
| // https://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html |
| template <typename Record> |
| class LockedQueue final { |
| inline void Enqueue(Record record); |
| inline bool Dequeue(Record* record); |
| inline bool IsEmpty() const; |
| inline bool Peek(Record* record) const; |
| mutable base::Mutex head_mutex_; |
| DISALLOW_COPY_AND_ASSIGN(LockedQueue); |
| #endif // V8_UTILS_LOCKED_QUEUE_H_ |