blob: 7713f668ee37860661151a04f923bdc29afbf05a [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
3/* 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
15using namespace frc;
16
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}