gtsam
Loading...
Searching...
No Matches
PriorityScheduler.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
3 * Atlanta, Georgia 30332-0415
4 * All Rights Reserved
5 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
6 * See LICENSE for the license information
7 * -------------------------------------------------------------------------- */
8
31
32#pragma once
33
35
36#include <queue>
37
38namespace gtsam {
39
40namespace detail {
41
45 using Metadata = int;
46
47 template <typename TaskPtr>
48 struct Compare {
49 bool operator()(const TaskPtr& a, const TaskPtr& b) const {
50 return a.metadata > b.metadata;
51 }
52 };
53
54 template <typename TaskPtr>
55 using Container =
56 std::priority_queue<TaskPtr, std::vector<TaskPtr>, Compare<TaskPtr>>;
57
58 template <typename TaskPtr>
59 static void push(Container<TaskPtr>& container, TaskPtr task) {
60 container.push(std::move(task));
61 }
62
63 template <typename TaskPtr>
64 static bool popLocal(Container<TaskPtr>& container, TaskPtr& out) {
65 if (container.empty()) return false;
66 out = container.top();
67 container.pop();
68 return true;
69 }
70
71 template <typename TaskPtr>
72 static bool popSteal(Container<TaskPtr>& container, TaskPtr& out) {
73 return popLocal(container, out);
74 }
75};
76
77} // namespace detail
78
92template <typename Y>
94
95} // namespace gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Scheduler< Y, detail::PrioritySchedulerPolicy > PriorityScheduler
Thread pool scheduler that prioritizes tasks by numeric priority.
Definition PriorityScheduler.h:93
Queue policy for PriorityScheduler: min-heap priority_queue by task priority.
Definition PriorityScheduler.h:44
Definition PriorityScheduler.h:48
Thread pool scheduler parameterized by a queue Policy.
Definition Scheduler.h:63
Policy-based work-stealing scheduler.