34 #include "../ThreadInterface.hpp" 36 #include "../fosi_internal_interface.hpp" 37 #include "../../Logger.hpp" 39 #include "../Mutex.hpp" 48 const char* name =
"main";
49 main_task->
name = strcpy( (
char*)malloc( (strlen(name) + 1) *
sizeof(
char)), name);
50 main_task->
thread = pthread_self();
51 pthread_attr_init( &(main_task->
attr) );
52 struct sched_param sp;
56 pthread_attr_setschedparam(&(main_task->
attr), &sp);
57 main_task->
priority = sp.sched_priority;
64 pthread_attr_destroy( &(main_task->
attr) );
65 free( main_task->
name );
66 main_task->
name = NULL;
72 unsigned cpu_affinity,
76 void * (*start_routine)(
void *),
87 if ( strlen(name) == 0 )
89 task->
name = strcpy( (
char*)malloc( (strlen(name) + 1) *
sizeof(
char)), name);
91 if ( (rv = pthread_attr_init(&(task->
attr))) != 0 ){
95 if ( (rv = pthread_attr_setschedpolicy(&(task->
attr), sched_type)) != 0){
98 pthread_attr_getschedpolicy(&(task->
attr), &rv );
99 assert( rv == sched_type );
101 struct sched_param sp;
102 sp.sched_priority=priority;
104 if ( (rv = pthread_attr_setschedparam(&(task->
attr), &sp)) != 0 ){
107 rv = pthread_create(&(task->
thread), &(task->
attr), start_routine, obj);
114 int ret = sched_yield();
116 perror(
"rtos_task_yield");
120 pthread_t
self = pthread_self();
121 if ( pthread_equal(
self, task->
thread) == 0 )
130 struct sched_param param;
135 if (pthread_getschedparam(task->
thread, &policy, ¶m) == 0) {
137 param.sched_priority = task->
priority;
140 return pthread_setschedparam( task->
thread, sched_type, ¶m);
148 struct sched_param param;
150 if ( task && task->
thread != 0 && pthread_getschedparam(task->
thread, &policy, ¶m) == 0)
158 mytask->
period = nanosecs;
165 mytask->
period = nanosecs;
193 if ( timeRemaining > 0 ) {
205 pthread_join( mytask->
thread, 0);
206 pthread_attr_destroy( &(mytask->
attr) );
213 if (*scheduler != SCHED_OTHER && *scheduler != SCHED_FIFO && *scheduler != SCHED_RR ) {
215 *scheduler = SCHED_OTHER;
228 log(
Warning) <<
"Forcing priority ("<<*priority<<
") of thread to 0." <<
endlog();
233 log(
Warning) <<
"Forcing priority ("<<*priority<<
") of thread to 63." <<
endlog();
243 struct sched_param param;
245 if( task && task->
thread != 0 && pthread_getschedparam(task->
thread, &policy, ¶m) == 0) {
248 param.sched_priority = priority;
251 return pthread_setschedparam( task->
thread, policy, ¶m);
260 struct sched_param param;
264 if ( task->
thread == 0 || pthread_getschedparam(task->
thread, &policy, ¶m) != 0)
266 return param.sched_priority;
286 return task->
name ? task->
name :
"(destroyed)";
326 (*m)->mutex.unlock();
int rtos_task_is_self(const RTOS_TASK *task)
int rtos_task_get_priority(const RTOS_TASK *task)
INTERNAL_QUAL void rtos_task_make_periodic(RTOS_TASK *mytask, NANO_TIME nanosecs)
unsigned int rtos_task_get_pid(const RTOS_TASK *task)
struct rt_mutex_impl_t rt_mutex_impl_t
NANO_TIME rtos_get_time_ns(void)
INTERNAL_QUAL int rtos_task_delete_main(RTOS_TASK *main_task)
int rtos_task_set_scheduler(RTOS_TASK *t, int sched_type)
static int rtos_nanosleep(const TIME_SPEC *rqtp, TIME_SPEC *rmtp)
int rtos_mutex_init(rt_mutex_t *m)
int rtos_task_set_cpu_affinity(RTOS_TASK *task, unsigned cpu_affinity)
unsigned rtos_task_get_cpu_affinity(const RTOS_TASK *task)
INTERNAL_QUAL int rtos_task_check_priority(int *scheduler, int *priority)
int rtos_mutex_destroy(rt_mutex_t *m)
void rtos_task_set_wait_period_policy(RTOS_TASK *task, int policy)
void rtos_task_delete(RTOS_TASK *mytask)
INTERNAL_QUAL void rtos_task_yield(RTOS_TASK *)
int rtos_task_set_priority(RTOS_TASK *task, int priority)
const char * rtos_task_get_name(const RTOS_TASK *task)
int rtos_task_check_scheduler(int *sched_type)
static TIME_SPEC ticks2timespec(TICK_TIME hrt)
int rtos_task_wait_period(RTOS_TASK *task)
int rtos_mutex_lock(rt_mutex_t *m)
An object oriented wrapper around a non recursive mutex.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
INTERNAL_QUAL int rtos_task_create_main(RTOS_TASK *main_task)
void rtos_task_set_period(RTOS_TASK *mytask, NANO_TIME nanosecs)
struct timespec TIME_SPEC
int rtos_mutex_unlock(rt_mutex_t *m)
static Logger::LogFunction endlog()
INTERNAL_QUAL int rtos_task_create(RTOS_TASK *task, int priority, unsigned cpu_affinity, const char *name, int sched_type, size_t stack_size, void *(*start_routine)(void *), ThreadInterface *obj)
int rtos_task_get_scheduler(const RTOS_TASK *t)