[hal] Refactor threads API (#8701)

Since sched_setscheduler() requires non-RT priorities to be 0, we can
use that as a sentinel value for disabling RT and condense the Java API
to just two functions with fewer parameters. The thread priority setter
is deprecated since only experts should use it.

The HAL Notifier thread priority setter was replaced with setting the
priority in the thread itself.

The C++ Notifier non-RT and RT constructors were deduplicated.

The real-time scheduler was changed from SCHED_FIFO to SCHED_RR, which
is SCHED_FIFO with threads allowed to run for a maximum time quantum
before yielding (100 ms by default).
This commit is contained in:
Tyler Veness
2026-04-06 08:49:43 -07:00
committed by GitHub
parent cc56c42d4c
commit 173ecd3d02
27 changed files with 188 additions and 388 deletions

View File

@@ -19,4 +19,3 @@ classes:
wpi::units::second_t:
Stop:
GetOverrun:
SetHALThreadPriority:

View File

@@ -157,11 +157,6 @@ class RobotStarter:
def _start(self, robot_cls: wpilib.RobotBase) -> bool:
hal.reportUsage("Language", "Python")
if not wpilib.Notifier.setHALThreadPriority(True, 40):
reportErrorInternal(
"Setting HAL Notifier RT priority to 40 failed", isWarning=True
)
isSimulation = wpilib.RobotBase.isSimulation()
# hack: initialize networktables before creating the robot

View File

@@ -155,8 +155,3 @@ int32_t PyNotifier::GetOverrun() const {
WPILIB_CheckErrorStatus(status, "GetNotifierOverrun");
return overrun;
}
bool PyNotifier::SetHALThreadPriority(bool realTime, int32_t priority) {
int32_t status = 0;
return HAL_SetNotifierThreadPriority(realTime, priority, &status);
}

View File

@@ -101,23 +101,6 @@ class PyNotifier {
*/
int32_t GetOverrun() const;
/**
* Sets the HAL notifier thread priority.
*
* The HAL notifier thread is responsible for managing the FPGA's notifier
* interrupt and waking up user's Notifiers when it's their time to run.
* Giving the HAL notifier thread real-time priority helps ensure the user's
* real-time Notifiers, if any, are notified to run in a timely manner.
*
* @param realTime Set to true to set a real-time priority, false for standard
* priority.
* @param priority Priority to set the thread to. For real-time, this is 1-99
* with 99 being highest. For non-real-time, this is forced to
* 0. See "man 7 sched" for more details.
* @return True on success.
*/
static bool SetHALThreadPriority(bool realTime, int32_t priority);
private:
// The thread waiting on the HAL alarm
py::object m_thread;