diff options
-rw-r--r-- | usr/actor.c | 6 | ||||
-rw-r--r-- | usr/actor.h | 20 |
2 files changed, 21 insertions, 5 deletions
diff --git a/usr/actor.c b/usr/actor.c index 000e66a..283d92b 100644 --- a/usr/actor.c +++ b/usr/actor.c @@ -43,7 +43,7 @@ actor_time_left(actor_t *thread, time_t current_time) ((int64_t)(b) - (int64_t)(a) < 0) void -actor_init(actor_t *thread, void (*callback)(void *), void *data) +__actor_init(actor_t *thread, void (*callback)(void *), void *data) { INIT_LIST_HEAD(&thread->list); thread->state = ACTOR_NOTSCHEDULED; @@ -188,10 +188,10 @@ actor_schedule(actor_t *thread) } void -actor_timer(actor_t *thread, uint32_t timeout_secs, void (*callback)(void *), +__actor_timer(actor_t *thread, uint32_t timeout_secs, void (*callback)(void *), void *data) { - actor_init(thread, callback, data); + __actor_init(thread, callback, data); actor_schedule_private(thread, timeout_secs, 0); } diff --git a/usr/actor.h b/usr/actor.h index f572f2e..a67eb36 100644 --- a/usr/actor.h +++ b/usr/actor.h @@ -19,9 +19,12 @@ #ifndef ACTOR_H #define ACTOR_H +#include <stdio.h> #include "types.h" #include "list.h" +#define ACTOR_NAME_LEN 128 + typedef enum actor_state_e { ACTOR_INVALID, ACTOR_WAITING, @@ -30,6 +33,7 @@ typedef enum actor_state_e { } actor_state_e; typedef struct actor { + char name[ACTOR_NAME_LEN]; struct list_head list; actor_state_e state; void *data; @@ -37,14 +41,26 @@ typedef struct actor { time_t ttschedule; } actor_t; -extern void actor_init(actor_t *thread, void (*callback)(void *), void * data); +extern void __actor_init(actor_t *thread, void (*callback)(void *), void * data); extern void actor_delete(actor_t *thread); extern void actor_schedule_head(actor_t *thread); extern void actor_schedule(actor_t *thread); -extern void actor_timer(actor_t *thread, uint32_t delay_secs, +extern void __actor_timer(actor_t *thread, uint32_t delay_secs, void (*callback)(void *), void *data); extern void actor_timer_mod(actor_t *thread, uint32_t new_delay_secs, void *data); extern void actor_poll(void); +#define actor_init(thread, callback, data) \ +do { \ + snprintf((thread)->name, ACTOR_NAME_LEN, #callback); \ + __actor_init(thread, callback, data); \ +} while (0) + +#define actor_timer(thread, timeout_secs, callback, data) \ +do { \ + snprintf((thread)->name, ACTOR_NAME_LEN, #callback); \ + __actor_timer(thread, timeout_secs, callback, data); \ +} while (0) + #endif /* ACTOR_H */ |