2016-01-02 03:02:34 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2016. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2014-05-02 17:54:01 -04:00
|
|
|
#include "HAL/Task.hpp"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 01:54:20 -07:00
|
|
|
#ifndef OK
|
|
|
|
|
#define OK 0
|
|
|
|
|
#endif /* OK */
|
|
|
|
|
#ifndef ERROR
|
|
|
|
|
#define ERROR (-1)
|
|
|
|
|
#endif /* ERROR */
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
#include <signal.h>
|
|
|
|
|
|
2015-11-26 00:08:32 -08:00
|
|
|
extern "C" {
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
STATUS verifyTaskID(TASK task) {
|
2014-08-14 00:07:02 -07:00
|
|
|
if (task != nullptr && pthread_kill(*task, 0) == 0) {
|
2013-12-15 18:30:16 -05:00
|
|
|
return OK;
|
|
|
|
|
} else {
|
|
|
|
|
return ERROR;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STATUS setTaskPriority(TASK task, int priority) {
|
2014-08-14 00:07:02 -07:00
|
|
|
int policy = 0;
|
|
|
|
|
struct sched_param param;
|
|
|
|
|
|
|
|
|
|
if (verifyTaskID(task) == OK &&
|
|
|
|
|
pthread_getschedparam(*task, &policy, ¶m) == 0) {
|
|
|
|
|
param.sched_priority = priority;
|
|
|
|
|
if (pthread_setschedparam(*task, SCHED_FIFO, ¶m) == 0) {
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return ERROR;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return ERROR;
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STATUS getTaskPriority(TASK task, int* priority) {
|
2014-08-14 00:07:02 -07:00
|
|
|
int policy = 0;
|
|
|
|
|
struct sched_param param;
|
|
|
|
|
|
|
|
|
|
if (verifyTaskID(task) == OK &&
|
|
|
|
|
pthread_getschedparam(*task, &policy, ¶m) == 0) {
|
|
|
|
|
*priority = param.sched_priority;
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return ERROR;
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
2015-11-26 00:08:32 -08:00
|
|
|
|
|
|
|
|
} // extern "C"
|