Files
allwpilib/cscore/src/main/native/linux/RunLoopHelpers.cpp

39 lines
899 B
C++
Raw Normal View History

// 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.
2025-11-07 19:56:21 -05:00
#include "wpi/cs/cscore_runloop.hpp"
2025-11-07 19:57:55 -05:00
#include "wpi/util/Synchronization.h"
2025-11-07 20:00:05 -05:00
static wpi::util::Event& GetInstance() {
static wpi::util::Event event;
return event;
}
2025-11-07 20:00:05 -05:00
namespace wpi::cs {
void RunMainRunLoop() {
2025-11-07 20:00:05 -05:00
wpi::util::Event& event = GetInstance();
wpi::util::WaitForObject(event.GetHandle());
}
int RunMainRunLoopTimeout(double timeout) {
2025-11-07 20:00:05 -05:00
wpi::util::Event& event = GetInstance();
bool timedOut = false;
2025-11-07 20:00:05 -05:00
bool signaled = wpi::util::WaitForObject(event.GetHandle(), timeout, &timedOut);
if (timedOut) {
return 3;
}
if (signaled) {
return 2;
}
return 1;
}
void StopMainRunLoop() {
2025-11-07 20:00:05 -05:00
wpi::util::Event& event = GetInstance();
event.Set();
}
2025-11-07 20:00:05 -05:00
} // namespace wpi::cs