Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 1 | // 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 4 | |
| 5 | #include "frc/Threads.h" |
| 6 | |
| 7 | #include <hal/FRCUsageReporting.h> |
| 8 | #include <hal/Threads.h> |
| 9 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 10 | #include "frc/Errors.h" |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 11 | |
| 12 | namespace frc { |
| 13 | |
| 14 | int 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 Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 19 | FRC_CheckErrorStatus(status, "GetThreadPriority"); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 20 | *isRealTime = rt; |
| 21 | return ret; |
| 22 | } |
| 23 | |
| 24 | int GetCurrentThreadPriority(bool* isRealTime) { |
| 25 | int32_t status = 0; |
| 26 | HAL_Bool rt = false; |
| 27 | auto ret = HAL_GetCurrentThreadPriority(&rt, &status); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 28 | FRC_CheckErrorStatus(status, "GetCurrentThreadPriority"); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 29 | *isRealTime = rt; |
| 30 | return ret; |
| 31 | } |
| 32 | |
| 33 | bool 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 Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 37 | FRC_CheckErrorStatus(status, "SetThreadPriority"); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 38 | return ret; |
| 39 | } |
| 40 | |
| 41 | bool SetCurrentThreadPriority(bool realTime, int priority) { |
| 42 | int32_t status = 0; |
| 43 | auto ret = HAL_SetCurrentThreadPriority(realTime, priority, &status); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 44 | FRC_CheckErrorStatus(status, "SetCurrentThreadPriority"); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 45 | return ret; |
| 46 | } |
| 47 | |
| 48 | } // namespace frc |