coroutine/cotask: add cotask_get_name() API

This commit is contained in:
Andrei Alexeyev 2023-03-30 04:17:30 +02:00
parent a13e6ae7a3
commit 10ecc9ff42
No known key found for this signature in database
GPG key ID: 72D26128040B9690
4 changed files with 14 additions and 6 deletions

View file

@ -17,6 +17,7 @@ void cosched_init(CoSched *sched) {
CoTask *_cosched_new_task(CoSched *sched, CoTaskFunc func, void *arg, size_t arg_size, bool is_subtask, CoTaskDebugInfo debug) {
assume(sched != NULL);
CoTask *task = cotask_new_internal(cotask_entry);
task->name = debug.label;
#ifdef CO_TASK_DEBUG
snprintf(task->debug_label, sizeof(task->debug_label), "#%i <%p> %s (%s:%i:%s)", task->unique_id, (void*)task, debug.label, debug.debug_info.file, debug.debug_info.line, debug.debug_info.func);

View file

@ -759,3 +759,7 @@ void cotask_force_finish(CoTask *task) {
cotask_free(task);
}
const char *cotask_get_name(CoTask *task) {
return task->name;
}

View file

@ -40,16 +40,17 @@ typedef struct CoWaitResult {
CoEventStatus event_status;
} CoWaitResult;
typedef struct CoTaskDebugInfo {
const char *label;
#ifdef CO_TASK_DEBUG
typedef struct CoTaskDebugInfo {
const char *label;
DebugInfo debug_info;
} CoTaskDebugInfo;
DebugInfo debug_info;
#endif
} CoTaskDebugInfo;
#ifdef CO_TASK_DEBUG
#define COTASK_DEBUG_INFO(label) ((CoTaskDebugInfo) { (label), _DEBUG_INFO_INITIALIZER_ })
#else
typedef char CoTaskDebugInfo;
#define COTASK_DEBUG_INFO(label) (0)
#define COTASK_DEBUG_INFO(label) ((CoTaskDebugInfo) { (label) })
#endif
typedef struct CoSched CoSched;
@ -72,6 +73,7 @@ void *cotask_malloc(CoTask *task, size_t size) attr_returns_allocated attr_mallo
EntityInterface *cotask_host_entity(CoTask *task, size_t ent_size, EntityType ent_type) attr_nonnull_all attr_returns_allocated;
void cotask_host_events(CoTask *task, uint num_events, CoEvent events[num_events]) attr_nonnull_all;
CoSched *cotask_get_sched(CoTask *task);
const char *cotask_get_name(CoTask *task) attr_nonnull(1);
BoxedTask cotask_box(CoTask *task);
CoTask *cotask_unbox(BoxedTask box);

View file

@ -55,6 +55,7 @@ struct CoTask {
CoTaskData *data;
uint32_t unique_id;
const char *name;
#ifdef CO_TASK_DEBUG
char debug_label[256];