mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal] Add HAL_Shutdown and simulation shutdown callbacks
This is useful for clean shutdown of simulation extensions.
This commit is contained in:
@@ -7,8 +7,11 @@
|
||||
|
||||
#include "hal/HAL.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
#include <wpi/spinlock.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
@@ -28,6 +31,8 @@
|
||||
using namespace hal;
|
||||
|
||||
static HAL_RuntimeType runtimeType{HAL_Mock};
|
||||
static wpi::spinlock gOnShutdownMutex;
|
||||
static std::vector<std::pair<void*, void (*)(void*)>> gOnShutdown;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
@@ -312,6 +317,22 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
||||
return true; // Add initialization if we need to at a later point
|
||||
}
|
||||
|
||||
void HAL_Shutdown(void) {
|
||||
std::vector<std::pair<void*, void (*)(void*)>> funcs;
|
||||
{
|
||||
std::scoped_lock lock(gOnShutdownMutex);
|
||||
funcs.swap(gOnShutdown);
|
||||
}
|
||||
for (auto&& func : funcs) {
|
||||
func.second(func.first);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_OnShutdown(void* param, void (*func)(void*)) {
|
||||
std::scoped_lock lock(gOnShutdownMutex);
|
||||
gOnShutdown.emplace_back(param, func);
|
||||
}
|
||||
|
||||
int64_t HAL_Report(int32_t resource, int32_t instanceNumber, int32_t context,
|
||||
const char* feature) {
|
||||
return 0; // Do nothing for now
|
||||
|
||||
Reference in New Issue
Block a user