Wildmeshing Toolkit
Loading...
Searching...
No Matches
src
wmtk
threading
serial_priority_queue.hpp
1
#pragma once
2
3
#include <queue>
4
#include <utility>
5
#include <vector>
6
7
namespace
wmtk::threading {
8
// ---------------------------------------------------------------------------
9
// serial_priority_queue: the same (used) interface as concurrent_priority_queue,
10
// minus the mutex, for queues that only ever have one thread touching them.
11
//
12
// The scheduler gives every task its own queue and only ever pops from, and pushes
13
// renewed operations back into, that one queue; the single queue that genuinely
14
// crosses threads is the overflow queue drained after the barrier. Paying for a
15
// lock/unlock pair on every pop and every renewal of a thread-private heap is pure
16
// overhead, so the private ones use this and only the shared one stays concurrent.
17
//
18
// Both are std::priority_queue underneath with the same comparator, so swapping one
19
// for the other cannot change pop order.
20
// ---------------------------------------------------------------------------
21
template
<
typename
T,
typename
Compare = std::less<T>>
22
class
serial_priority_queue
23
{
24
std::priority_queue<T, std::vector<T>, Compare> m_queue;
25
26
public
:
27
bool
try_pop(T& out)
28
{
29
if
(m_queue.empty()) {
30
return
false
;
31
}
32
out = m_queue.top();
33
m_queue.pop();
34
return
true
;
35
}
36
37
void
push(
const
T& v) { m_queue.push(v); }
38
39
template
<
typename
... Args>
40
void
emplace(Args&&... args)
41
{
42
m_queue.emplace(std::forward<Args>(args)...);
43
}
44
45
std::size_t size()
const
{
return
m_queue.size(); }
46
bool
empty()
const
{
return
m_queue.empty(); }
47
};
48
49
}
// namespace wmtk::threading
wmtk::threading::serial_priority_queue
Definition
serial_priority_queue.hpp:23
Generated by
1.9.8