[wpiutil] Add custom priority queue implementation (#2770)

This returns the removed object from pop() to avoid copies.
This commit is contained in:
Tyler Veness
2020-10-04 12:49:23 -07:00
committed by GitHub
parent 8e538aa82f
commit 96e26247d7
3 changed files with 122 additions and 44 deletions

View File

@@ -11,8 +11,8 @@
#include <hal/Notifier.h>
#include <wpi/Format.h>
#include <wpi/PriorityQueue.h>
#include <wpi/SmallString.h>
#include <wpi/priority_queue.h>
#include <wpi/raw_ostream.h>
#include "frc/DriverStation.h"
@@ -34,7 +34,8 @@ class Watchdog::Impl {
wpi::mutex m_mutex;
std::atomic<HAL_NotifierHandle> m_notifier;
wpi::PriorityQueue<Watchdog*, std::vector<Watchdog*>, DerefGreater<Watchdog*>>
wpi::priority_queue<Watchdog*, std::vector<Watchdog*>,
DerefGreater<Watchdog*>>
m_watchdogs;
void UpdateAlarm();
@@ -97,8 +98,7 @@ void Watchdog::Impl::Main() {
// If the condition variable timed out, that means a Watchdog timeout
// has occurred, so call its timeout function.
auto watchdog = m_watchdogs.top();
m_watchdogs.pop();
auto watchdog = m_watchdogs.pop();
units::second_t now{curTime * 1e-6};
if (now - watchdog->m_lastTimeoutPrintTime > kMinPrintPeriod) {