2020-12-26 14:12:05 -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.
|
2016-12-01 21:06:19 -08:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/Threads.h"
|
2016-12-01 21:06:19 -08:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include <hal/Threads.h>
|
2017-08-27 00:11:52 -07:00
|
|
|
|
2021-04-18 20:35:29 -07:00
|
|
|
#include "frc/Errors.h"
|
2016-12-01 21:06:19 -08:00
|
|
|
|
2019-03-03 15:39:59 -08:00
|
|
|
namespace frc {
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2016-12-01 21:06:19 -08:00
|
|
|
int GetThreadPriority(std::thread& thread, bool* isRealTime) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_Bool rt = false;
|
|
|
|
|
auto native = thread.native_handle();
|
|
|
|
|
auto ret = HAL_GetThreadPriority(&native, &rt, &status);
|
2022-10-19 10:49:27 -07:00
|
|
|
FRC_CheckErrorStatus(status, "GetThreadPriority");
|
2016-12-01 21:06:19 -08:00
|
|
|
*isRealTime = rt;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GetCurrentThreadPriority(bool* isRealTime) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_Bool rt = false;
|
|
|
|
|
auto ret = HAL_GetCurrentThreadPriority(&rt, &status);
|
2022-10-19 10:49:27 -07:00
|
|
|
FRC_CheckErrorStatus(status, "GetCurrentThreadPriority");
|
2016-12-01 21:06:19 -08:00
|
|
|
*isRealTime = rt;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SetThreadPriority(std::thread& thread, bool realTime, int priority) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
auto native = thread.native_handle();
|
|
|
|
|
auto ret = HAL_SetThreadPriority(&native, realTime, priority, &status);
|
2022-10-19 10:49:27 -07:00
|
|
|
FRC_CheckErrorStatus(status, "SetThreadPriority");
|
2016-12-01 21:06:19 -08:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SetCurrentThreadPriority(bool realTime, int priority) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
auto ret = HAL_SetCurrentThreadPriority(realTime, priority, &status);
|
2022-10-19 10:49:27 -07:00
|
|
|
FRC_CheckErrorStatus(status, "SetCurrentThreadPriority");
|
2016-12-01 21:06:19 -08:00
|
|
|
return ret;
|
|
|
|
|
}
|
2019-03-03 15:39:59 -08:00
|
|
|
|
|
|
|
|
} // namespace frc
|