22 #ifndef _TASK_COMPAT_H_ 23 #define _TASK_COMPAT_H_ 27 #include <sys/types.h> 33 #define STACK_SIZE 6000 34 #elif defined(__x86__) || defined(__x86_64__) 35 #define STACK_SIZE 1000000 42 ::printf("Error: %d\n", val); \ 46 #define pcheck_print(val, checkval, extra_action) \ 47 if (val != checkval) { \ 48 ::printf("Error: %d\n", val); \ 52 #define pcheck_attr(val, attr) \ 54 ::printf("Destroying ERROR:%d\n", val); \ 55 pthread_attr_destroy(attr); \ 83 int create_task(
void *(*loop)(
void *),
const int pri,
const int s_policy,
84 int stack_size = STACK_SIZE) {
85 pthread_attr_t attribute = {0};
86 struct sched_param parameter;
90 pcheck(pthread_attr_init(&attribute));
95 pcheck_attr(pthread_attr_setstacksize(&attribute, stack_size), &attribute);
96 DEBUGV(
"Stack:%d\n", stack_size);
101 pcheck_attr(pthread_attr_setschedparam(&attribute, ¶meter), &attribute);
105 pcheck(pthread_attr_destroy(&attribute));
112 task(
char const *
id,
void *(*loop)(
void *),
const int prio,
113 const int sch_policy,
const useconds_t p)
117 [](
void *tsk) ->
void * {
118 struct task *ttask = (
struct task *)tsk;
119 struct timespec now = {0}, next = {0}, tmp = {0};
127 clock_gettime(CLOCK_REALTIME, &next);
133 clock_gettime(CLOCK_REALTIME, &now);
136 struct timespec spec_p;
142 DEBUGV3(
"timespecp: %lu,%lu\n", spec_p.tv_sec, spec_p.tv_nsec);
143 DEBUGV3(
"timespec: %lu,%lu\n", next.tv_sec, next.tv_nsec);
147 DEBUGV3(
"timespec2: %lu,%lu\n", next.tv_sec, next.tv_nsec);
148 DEBUGV3(
"timespecnow: %lu,%lu\n", now.tv_sec, now.tv_nsec);
153 DEBUGV_ERROR(
"Task is missing their deadline for %lu s.%lu ns\n",
154 tmp.tv_sec, tmp.tv_nsec);
157 pthread_mutex_lock(&ttask->
fmtx);
159 pthread_cond_timedwait(&ttask->
cond, &ttask->
fmtx, &next),
161 pthread_mutex_unlock(&ttask->
fmtx);
179 #endif //_TASK_COMPAT_H_ pthread_t thread
Definition: task_compat.h:63
#define pcheck_print(val, checkval, extra_action)
Definition: task_compat.h:46
pthread_mutex_t fmtx
Definition: task_compat.h:65
#define pcheck(val)
Definition: task_compat.h:40
const useconds_t period
Definition: task_compat.h:71
#define P_OK
Definition: task_compat.h:38
Definition: task_compat.h:59
#define DEBUGV_ERROR(...)
Definition: debug_compat.h:85
void *(* run)(void *)
Definition: task_compat.h:81
status
Definition: task_compat.h:59
Definition: task_compat.h:59
pthread_cond_t cond
Definition: task_compat.h:67
#define DEBUGV3(...)
Definition: debug_compat.h:84
char const * tid
Definition: task_compat.h:69
#define DEBUGV(...)
Definition: debug_compat.h:83
Definition: task_compat.h:59
#define pcheck_attr(val, attr)
Definition: task_compat.h:52
#define timespecadd(tsp, usp, vsp)
Definition: time_compat.h:105
Definition: task_compat.h:59
Definition: task_compat.h:61
task(char const *id, void *(*loop)(void *), const int prio, const int sch_policy, const useconds_t p)
Definition: task_compat.h:112
int create_task(void *(*loop)(void *), const int pri, const int s_policy, int stack_size=STACK_SIZE)
Definition: task_compat.h:83
Definition: task_compat.h:59
status st
Definition: task_compat.h:79
#define useconds_t2timespec(tsp, vsp)
Definition: time_compat.h:125
const int sched_policy
Definition: task_compat.h:73
Definition: task_compat.h:59
bool running
Definition: task_compat.h:77
#define timespeccmp(tsp, usp, cmp)
Definition: time_compat.h:101
#define timespecsub(tsp, usp, vsp)
Definition: time_compat.h:115
const int priority
Definition: task_compat.h:75