27 #include <alchemy/task.h> 28 #include <alchemy/timer.h> 32 #include <sys/resource.h> 45 struct rlimit rlim = {RLIM_INFINITY, RLIM_INFINITY};
46 setrlimit(RLIMIT_MEMLOCK, &rlim);
48 if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
49 ERROR_MSG(
"RTOS:Xenomai::initiate : failed to lock memory.\n");
72 rt_task_set_mode(0, T_WARNSW,
nullptr);
73 retval = rt_task_create(&xenomai_task,
"Real-Time Task", 0, 50, 0);
75 ERROR_MSG(
"RT::OS::createTask : failed to create task\n");
88 auto wrapper = [](
void* args)
90 auto* transferred_args =
reinterpret_cast<struct wrapper_args_t*
>(args);
93 ERROR_MSG(
"RT::OS::createTask : RT::OS::initiate() : {}",
99 transferred_args->fn(transferred_args->args);
104 struct wrapper_args_t wrapper_args
110 retval = rt_task_start(&xenomai_task, wrapper, &wrapper_args);
112 ERROR_MSG(
"RT::OS::createTask : failed to start task\n");
116 task->
thread_id = std::any(xenomai_task);
122 auto xenomai_task = std::any_cast<RT_TASK>(task->
thread_id);
123 rt_task_delete(&xenomai_task);
133 return rt_timer_ticks2ns(rt_timer_read());
153 auto wakeup_time =
static_cast<SRTIME
>(task->
next_t);
155 rt_task_sleep_until(rt_timer_ns2ticks(wakeup_time));
164 if (pthread_setname_np(thread.native_handle(), name.c_str()) != 0) {
165 ERROR_MSG(
"RT::OS::renameOSThread : unable to set name to thread");
void ERROR_MSG(const std::string &errmsg, Args... args)
int createTask(Task *task, void(*func)(void *), void *arg)
int setPeriod(Task *task, int64_t period)
void shutdown(RT::OS::Task *task)
void sleepTimestep(Task *task)
void renameOSThread(std::thread &thread, const std::string &name)
int initiate(RT::OS::Task *task)
void deleteTask(Task *task)
const int64_t DEFAULT_PERIOD
thread_local int64_t * RT_PERIOD
thread_local bool realtime_key