Timers in a task context

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Apr 11 06:19:36 UTC 2018


On 10/04/18 14:20, Matthew J Fletcher wrote:
> Hi
>
> It would be good to know if rtems_task_self() is expected to return 
> the 'TIME' a.k.a rtems_timer_initiate_server() task id, when a timer 
> created with rtems_timer_server_fire_after() fires.

The use of rtems_task_self() in timer routines is a bad application 
behaviour from my point of view. The execution context of the timer 
routines is an implementation detail.

>
> If it is then i will have to make up some work around, as quite a bit 
> of code thats coming over from ThreadX depends on, it returning the 
> previous 'user' task, not the previous 'system' task.

You can easily fix this with some glue code, e.g.

typedef struct your_timer {
   rtems_id task_which_created_this_timer;
   rtems_id timer;
   void *arg;
   void (*handler)(struct your_timer *, void *);
} your_timer;

void create_timer(your_timer *t)
{
   t->task_which_created_this_timer = rtems_task_self();
   rtems_timer_create(..., &t->timer);
}

void timer_wrapper(rtems_id timer, void *arg)
{
   your_timer *t = arg;

   (*t->handler)(t, t->arg);
}

void fire_timer(your_timer *t, ...)
{
   rtems_timer_fire_after(..., timer_wrapper, t);
}

rtems_id get_task_which_created_this_timer(const your_timer *t)
{
    return t->task_which_created_this_timer;
}

>
> Personally it does feel wrong that the behavior of rtems_task_self() 
> changes behavior depending if you use the timer server or not.

rtems_task_self() returns the id of the executing thread.

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.




More information about the users mailing list