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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "Threads.h"
|
|
|
|
|
|
2017-08-27 00:11:52 -07:00
|
|
|
#include <HAL/HAL.h>
|
|
|
|
|
#include <HAL/Threads.h>
|
|
|
|
|
|
2016-12-01 21:06:19 -08:00
|
|
|
#include "ErrorBase.h"
|
|
|
|
|
|
|
|
|
|
namespace frc {
|
|
|
|
|
/**
|
|
|
|
|
* Get the thread priority for the specified thread.
|
|
|
|
|
*
|
2017-11-16 00:33:51 -08:00
|
|
|
* @param thread Reference to the thread to get the priority for.
|
|
|
|
|
* @param isRealTime Set to true if thread is realtime, otherwise false.
|
2016-12-01 21:06:19 -08:00
|
|
|
* @return The current thread priority. Scaled 1-99, with 1 being highest.
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the thread priority for the current thread
|
|
|
|
|
*
|
2017-11-16 00:33:51 -08:00
|
|
|
* @param isRealTime Set to true if thread is realtime, otherwise false.
|
2016-12-01 21:06:19 -08:00
|
|
|
* @return The current thread priority. Scaled 1-99.
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the thread priority for the specified thread
|
|
|
|
|
*
|
2017-11-16 00:33:51 -08:00
|
|
|
* @param thread Reference to the thread to set the priority of.
|
2016-12-01 21:06:19 -08:00
|
|
|
* @param realTime Set to true to set a realtime priority, false for standard
|
2017-11-16 00:33:51 -08:00
|
|
|
* priority.
|
2016-12-01 21:06:19 -08:00
|
|
|
* @param priority Priority to set the thread to. Scaled 1-99, with 1 being
|
2017-11-16 00:33:51 -08:00
|
|
|
* highest. On RoboRIO, priority is ignored for non realtime
|
|
|
|
|
* setting.
|
2016-12-01 21:06:19 -08:00
|
|
|
*
|
|
|
|
|
* @return The success state of setting the priority
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the thread priority for the current thread
|
|
|
|
|
*
|
|
|
|
|
* @param realTime Set to true to set a realtime priority, false for standard
|
2017-11-16 00:33:51 -08:00
|
|
|
* priority.
|
2016-12-01 21:06:19 -08:00
|
|
|
* @param priority Priority to set the thread to. Scaled 1-99, with 1 being
|
2017-11-16 00:33:51 -08:00
|
|
|
* highest. On RoboRIO, priority is ignored for non realtime
|
|
|
|
|
* setting.
|
2016-12-01 21:06:19 -08:00
|
|
|
*
|
|
|
|
|
* @return The success state of setting the priority
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
} // namespace frc
|