2016-12-01 21:06:19 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
2016-12-01 21:06:19 -08:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
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/HAL.h>
|
|
|
|
|
#include <hal/Threads.h>
|
2017-08-27 00:11:52 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/ErrorBase.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);
|
|
|
|
|
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
|
|
|
|
*isRealTime = rt;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GetCurrentThreadPriority(bool* isRealTime) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_Bool rt = false;
|
|
|
|
|
auto ret = HAL_GetCurrentThreadPriority(&rt, &status);
|
|
|
|
|
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
|
|
|
|
*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);
|
|
|
|
|
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SetCurrentThreadPriority(bool realTime, int priority) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
auto ret = HAL_SetCurrentThreadPriority(realTime, priority, &status);
|
|
|
|
|
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2019-03-03 15:39:59 -08:00
|
|
|
|
|
|
|
|
} // namespace frc
|