 |
LibraryLink Utilities
3.0.1
Modern C++ wrapper over LibraryLink and WSTP
|
Go to the documentation of this file.
6 #ifndef LLU_ASYNC_WORKSTEALINGQUEUE_H
7 #define LLU_ASYNC_WORKSTEALINGQUEUE_H
11 namespace LLU::Async {
19 template<
typename BaseQueue>
21 using DataType =
typename BaseQueue::value_type;
24 mutable std::mutex theMutex;
32 std::lock_guard<std::mutex> lock(theMutex);
33 theQueue.push_front(std::move(data));
40 [[nodiscard]]
bool empty()
const {
41 std::lock_guard<std::mutex> lock(theMutex);
42 return theQueue.empty();
50 [[nodiscard]]
bool tryPop(DataType& res) {
51 std::lock_guard<std::mutex> lock(theMutex);
52 if (theQueue.empty()) {
55 res = std::move(theQueue.front());
66 std::lock_guard<std::mutex> lock(theMutex);
67 if (theQueue.empty()) {
70 res = std::move(theQueue.back());
77 #endif // LLU_ASYNC_WORKSTEALINGQUEUE_H
bool tryPop(DataType &res)
Try to pop a task from the beginning of the queue in a non-blocking way.
Definition: WorkStealingQueue.h:50
bool empty() const
Check if the queue is empty.
Definition: WorkStealingQueue.h:40
void push(DataType data)
Push new element to the beginning of the queue.
Definition: WorkStealingQueue.h:31
bool trySteal(DataType &res)
Try to pop a task from the end of the queue (this is what we call "stealing") in a non-blocking way.
Definition: WorkStealingQueue.h:65
Wrapper class around a queue, that provides the interface for work stealing.
Definition: WorkStealingQueue.h:20