mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Removes statics from hal sim (#825)
Based off of #824, the equivelent in sim.
This commit is contained in:
committed by
Peter Johnson
parent
8bd48d6c34
commit
d2e7a90f41
@@ -47,13 +47,22 @@ class NotifierHandleContainer
|
||||
}
|
||||
};
|
||||
|
||||
static NotifierHandleContainer notifierHandles;
|
||||
static NotifierHandleContainer* notifierHandles;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeNotifier() {
|
||||
static NotifierHandleContainer nH;
|
||||
notifierHandles = &nH;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
extern "C" {
|
||||
|
||||
HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
|
||||
std::shared_ptr<Notifier> notifier = std::make_shared<Notifier>();
|
||||
HAL_NotifierHandle handle = notifierHandles.Allocate(notifier);
|
||||
HAL_NotifierHandle handle = notifierHandles->Allocate(notifier);
|
||||
if (handle == HAL_kInvalidHandle) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
@@ -62,7 +71,7 @@ HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
|
||||
}
|
||||
|
||||
void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
auto notifier = notifierHandles.Get(notifierHandle);
|
||||
auto notifier = notifierHandles->Get(notifierHandle);
|
||||
if (!notifier) return;
|
||||
|
||||
{
|
||||
@@ -74,7 +83,7 @@ void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
}
|
||||
|
||||
void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
auto notifier = notifierHandles.Free(notifierHandle);
|
||||
auto notifier = notifierHandles->Free(notifierHandle);
|
||||
if (!notifier) return;
|
||||
|
||||
// Just in case HAL_StopNotifier() wasn't called...
|
||||
@@ -88,7 +97,7 @@ void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
|
||||
void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
uint64_t triggerTime, int32_t* status) {
|
||||
auto notifier = notifierHandles.Get(notifierHandle);
|
||||
auto notifier = notifierHandles->Get(notifierHandle);
|
||||
if (!notifier) return;
|
||||
|
||||
{
|
||||
@@ -104,7 +113,7 @@ void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
|
||||
void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
int32_t* status) {
|
||||
auto notifier = notifierHandles.Get(notifierHandle);
|
||||
auto notifier = notifierHandles->Get(notifierHandle);
|
||||
if (!notifier) return;
|
||||
|
||||
{
|
||||
@@ -115,7 +124,7 @@ void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
|
||||
uint64_t HAL_WaitForNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
int32_t* status) {
|
||||
auto notifier = notifierHandles.Get(notifierHandle);
|
||||
auto notifier = notifierHandles->Get(notifierHandle);
|
||||
if (!notifier) return 0;
|
||||
|
||||
std::unique_lock<wpi::mutex> lock(notifier->mutex);
|
||||
|
||||
Reference in New Issue
Block a user