mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[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:
@@ -19,4 +19,3 @@ classes:
|
||||
wpi::units::second_t:
|
||||
Stop:
|
||||
GetOverrun:
|
||||
SetHALThreadPriority:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user