diff options
author | Wenchao Hao <haowenchao@huawei.com> | 2022-02-01 23:30:35 +0800 |
---|---|---|
committer | Wenchao Hao <haowenchao@huawei.com> | 2022-02-02 00:54:45 +0800 |
commit | 3cf5539b9f531295db29401d0b9346881a4b08a0 (patch) | |
tree | a4763b1c237baf5acc10efae45050ffabd9ff890 /usr | |
parent | 68c04a3bb0c0506566cbe6f884f4d9f612636350 (diff) | |
download | open-iscsi-3cf5539b9f531295db29401d0b9346881a4b08a0.tar.gz |
actor: add name to struct actor and init it with function name
Previous actor log makes it hard to figure out what
is going on in the thread, such as:
"deleting a scheduled/waiting thread!"
We only know a thread is deleted, while no other info
like what this thread is about to do and which thread
it is. Logs like following seems better:
"deleting a scheduled/waiting thread 01111e48: session_conn_error !"
It tells thread with id 01111e48, which is going to executed
function "session_conn_error" is deleted.
The commit tries to give name to each thread, the name
is going to be printed with previous messages to make
the log easy to read.
Signed-off-by: Wenchao Hao <haowenchao@huawei.com>
Diffstat (limited to 'usr')
-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 */ |