blob: 798e86a4d62e84335f7e7e73b63b63e7dfb98a88 [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
10#include <hal/HAL.h>
11#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);
22 wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
23 *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);
31 wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
32 *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);
40 wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
41 return ret;
42}
43
44bool SetCurrentThreadPriority(bool realTime, int priority) {
45 int32_t status = 0;
46 auto ret = HAL_SetCurrentThreadPriority(realTime, priority, &status);
47 wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
48 return ret;
49}
James Kuszmaul4f3ad3c2019-12-01 16:35:21 -080050
51} // namespace frc