blob: 7b1e647c7c2dbe01ff5f3604e9b8922c8ec899eb [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001/*----------------------------------------------------------------------------*/
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -08002/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
Brian Silverman41cdd3e2019-01-19 19:48:58 -08003/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
6/*----------------------------------------------------------------------------*/
7
8#include "frc/Threads.h"
9
James Kuszmaul4b81d302019-12-14 20:53:14 -080010#include <hal/FRCUsageReporting.h>
Brian Silverman41cdd3e2019-01-19 19:48:58 -080011#include <hal/Threads.h>
12
13#include "frc/ErrorBase.h"
14
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -080015namespace frc {
Brian Silverman41cdd3e2019-01-19 19:48:58 -080016
17int GetThreadPriority(std::thread& thread, bool* isRealTime) {
18 int32_t status = 0;
19 HAL_Bool rt = false;
20 auto native = thread.native_handle();
21 auto ret = HAL_GetThreadPriority(&native, &rt, &status);
James Kuszmaul4b81d302019-12-14 20:53:14 -080022 wpi_setGlobalHALError(status);
Brian Silverman41cdd3e2019-01-19 19:48:58 -080023 *isRealTime = rt;
24 return ret;
25}
26
27int GetCurrentThreadPriority(bool* isRealTime) {
28 int32_t status = 0;
29 HAL_Bool rt = false;
30 auto ret = HAL_GetCurrentThreadPriority(&rt, &status);
James Kuszmaul4b81d302019-12-14 20:53:14 -080031 wpi_setGlobalHALError(status);
Brian Silverman41cdd3e2019-01-19 19:48:58 -080032 *isRealTime = rt;
33 return ret;
34}
35
36bool SetThreadPriority(std::thread& thread, bool realTime, int priority) {
37 int32_t status = 0;
38 auto native = thread.native_handle();
39 auto ret = HAL_SetThreadPriority(&native, realTime, priority, &status);
James Kuszmaul4b81d302019-12-14 20:53:14 -080040 wpi_setGlobalHALError(status);
Brian Silverman41cdd3e2019-01-19 19:48:58 -080041 return ret;
42}
43
44bool SetCurrentThreadPriority(bool realTime, int priority) {
45 int32_t status = 0;
46 auto ret = HAL_SetCurrentThreadPriority(realTime, priority, &status);
James Kuszmaul4b81d302019-12-14 20:53:14 -080047 wpi_setGlobalHALError(status);
Brian Silverman41cdd3e2019-01-19 19:48:58 -080048 return ret;
49}
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -080050
51} // namespace frc