2022-12-25 07:36:00 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
|
|
2022-12-25 11:37:59 -08:00
|
|
|
#include <wpi/Synchronization.h>
|
|
|
|
|
|
2022-12-25 07:36:00 -08:00
|
|
|
#include "cscore_runloop.h"
|
|
|
|
|
|
2022-12-25 11:37:59 -08:00
|
|
|
static wpi::Event& GetInstance() {
|
|
|
|
|
static wpi::Event event;
|
|
|
|
|
return event;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-25 07:36:00 -08:00
|
|
|
namespace cs {
|
2025-02-10 07:23:04 -08:00
|
|
|
|
2022-12-25 11:37:59 -08:00
|
|
|
void RunMainRunLoop() {
|
|
|
|
|
wpi::Event& event = GetInstance();
|
|
|
|
|
wpi::WaitForObject(event.GetHandle());
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-10 07:23:04 -08:00
|
|
|
int RunMainRunLoopTimeout(double timeout) {
|
2022-12-25 11:37:59 -08:00
|
|
|
wpi::Event& event = GetInstance();
|
|
|
|
|
bool timedOut = false;
|
2025-02-10 07:23:04 -08:00
|
|
|
bool signaled = wpi::WaitForObject(event.GetHandle(), timeout, &timedOut);
|
2022-12-25 11:37:59 -08:00
|
|
|
if (timedOut) {
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
if (signaled) {
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StopMainRunLoop() {
|
|
|
|
|
wpi::Event& event = GetInstance();
|
|
|
|
|
event.Set();
|
2022-12-25 07:36:00 -08:00
|
|
|
}
|
2025-02-10 07:23:04 -08:00
|
|
|
|
2022-12-25 07:36:00 -08:00
|
|
|
} // namespace cs
|