Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2016. 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 | |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 8 | #include "HAL/Task.hpp" |
| 9 | |
| 10 | #ifndef OK |
| 11 | #define OK 0 |
| 12 | #endif /* OK */ |
| 13 | #ifndef ERROR |
| 14 | #define ERROR (-1) |
| 15 | #endif /* ERROR */ |
| 16 | |
| 17 | #include <signal.h> |
| 18 | |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 19 | extern "C" { |
| 20 | |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 21 | STATUS verifyTaskID(TASK task) { |
| 22 | if (task != nullptr && pthread_kill(*task, 0) == 0) { |
| 23 | return OK; |
| 24 | } else { |
| 25 | return ERROR; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | STATUS setTaskPriority(TASK task, int priority) { |
| 30 | int policy = 0; |
| 31 | struct sched_param param; |
| 32 | |
| 33 | if (verifyTaskID(task) == OK && |
| 34 | pthread_getschedparam(*task, &policy, ¶m) == 0) { |
| 35 | param.sched_priority = priority; |
| 36 | if (pthread_setschedparam(*task, SCHED_FIFO, ¶m) == 0) { |
| 37 | return OK; |
| 38 | } |
| 39 | else { |
| 40 | return ERROR; |
| 41 | } |
| 42 | } |
| 43 | else { |
| 44 | return ERROR; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | STATUS getTaskPriority(TASK task, int* priority) { |
| 49 | int policy = 0; |
| 50 | struct sched_param param; |
| 51 | |
| 52 | if (verifyTaskID(task) == OK && |
| 53 | pthread_getschedparam(*task, &policy, ¶m) == 0) { |
| 54 | *priority = param.sched_priority; |
| 55 | return OK; |
| 56 | } |
| 57 | else { |
| 58 | return ERROR; |
| 59 | } |
| 60 | } |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 61 | |
| 62 | } // extern "C" |