-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.cpp
More file actions
35 lines (29 loc) · 721 Bytes
/
Queue.cpp
File metadata and controls
35 lines (29 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// Created by theo on 5/22/2021.
//
#include "Queue.h"
#include "Runnable.h"
#include "mtlNamespce.h"
#include <queue>
#include <mutex>
#include <optional>
#include <functional>
#include "Runnable.h"
bool mtl::Queue::empty() {
return runnablesQ.empty();
}
unsigned long mtl::Queue::size() const {
std::lock_guard<std::mutex> lock(qMutex);
return runnablesQ.size();
}
std::optional<void*> mtl::Queue::pop() {
std::lock_guard<std::mutex> lock(qMutex);
if (runnablesQ.empty()) return {};
Runnable* tmp = runnablesQ.front();
runnablesQ.pop();
return (void*)tmp;
}
void mtl::Queue::push(mtl::Runnable *item) {
std::lock_guard<std::mutex> lock(qMutex);
runnablesQ.push(item);
}