blob: 3ecab5569a69242d4e0df99aa70b8ac5a0de7c68 [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
Brian Silverman8fce7482020-01-05 13:18:21 -08004
5#include "frc/Threads.h"
6
7#include <hal/FRCUsageReporting.h>
8#include <hal/Threads.h>
9
Austin Schuh812d0d12021-11-04 20:16:48 -070010#include "frc/Errors.h"
Brian Silverman8fce7482020-01-05 13:18:21 -080011
12namespace frc {
13
14int GetThreadPriority(std::thread& thread, bool* isRealTime) {
15 int32_t status = 0;
16 HAL_Bool rt = false;
17 auto native = thread.native_handle();
18 auto ret = HAL_GetThreadPriority(&native, &rt, &status);
James Kuszmaulcf324122023-01-14 14:07:17 -080019 FRC_CheckErrorStatus(status, "GetThreadPriority");
Brian Silverman8fce7482020-01-05 13:18:21 -080020 *isRealTime = rt;
21 return ret;
22}
23
24int GetCurrentThreadPriority(bool* isRealTime) {
25 int32_t status = 0;
26 HAL_Bool rt = false;
27 auto ret = HAL_GetCurrentThreadPriority(&rt, &status);
James Kuszmaulcf324122023-01-14 14:07:17 -080028 FRC_CheckErrorStatus(status, "GetCurrentThreadPriority");
Brian Silverman8fce7482020-01-05 13:18:21 -080029 *isRealTime = rt;
30 return ret;
31}
32
33bool SetThreadPriority(std::thread& thread, bool realTime, int priority) {
34 int32_t status = 0;
35 auto native = thread.native_handle();
36 auto ret = HAL_SetThreadPriority(&native, realTime, priority, &status);
James Kuszmaulcf324122023-01-14 14:07:17 -080037 FRC_CheckErrorStatus(status, "SetThreadPriority");
Brian Silverman8fce7482020-01-05 13:18:21 -080038 return ret;
39}
40
41bool SetCurrentThreadPriority(bool realTime, int priority) {
42 int32_t status = 0;
43 auto ret = HAL_SetCurrentThreadPriority(realTime, priority, &status);
James Kuszmaulcf324122023-01-14 14:07:17 -080044 FRC_CheckErrorStatus(status, "SetCurrentThreadPriority");
Brian Silverman8fce7482020-01-05 13:18:21 -080045 return ret;
46}
47
48} // namespace frc