Make Watchdog use single thread dispatch (#1347)

Notifier has one thread per instance because the callbacks must be
asynchronous. Watchdog callbacks can be synchronous, so this overhead
can be done away with via a scheduler thread akin to what the HAL
Notifier does.
This commit is contained in:
Tyler Veness
2018-12-01 00:05:33 -08:00
committed by Peter Johnson
parent 99033481e0
commit 3b33abfc7b
7 changed files with 730 additions and 67 deletions

View File

@@ -0,0 +1,40 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#ifndef WPIUTIL_WPI_PRIORITYQUEUE_H_
#define WPIUTIL_WPI_PRIORITYQUEUE_H_
#include <algorithm>
#include <functional>
#include <queue>
#include <vector>
namespace wpi {
/**
* This class adds a method for removing all elements from the priority queue
* matching the given value.
*/
template <class T, class Container = std::vector<T>,
class Compare = std::less<typename Container::value_type>>
class PriorityQueue : public std::priority_queue<T, Container, Compare> {
public:
bool remove(const T& value) {
auto it = std::find(this->c.begin(), this->c.end(), value);
if (it != this->c.end()) {
this->c.erase(it);
std::make_heap(this->c.begin(), this->c.end(), this->comp);
return true;
} else {
return false;
}
}
};
} // namespace wpi
#endif // WPIUTIL_WPI_PRIORITYQUEUE_H_