From 2b7e2902dd6cc215cf074a8eeb80ecfbb5ae58bb Mon Sep 17 00:00:00 2001 From: vityaman Date: Thu, 21 Nov 2024 11:18:39 +0300 Subject: [PATCH] submit returns task --- source/coroed/api/task.h | 16 +++++++--------- source/coroed/sched/schedy.c | 9 +++++---- source/coroed/sched/schedy.h | 3 ++- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/source/coroed/api/task.h b/source/coroed/api/task.h index 3e5d09a..fbd71e1 100644 --- a/source/coroed/api/task.h +++ b/source/coroed/api/task.h @@ -2,18 +2,16 @@ #include "coroed/sched/uthread.h" -#define YIELD \ - do { \ - task_yield(__self); \ - } while (false) +#define YIELD task_yield(__self) -#define GO(entry, argument) \ - do { \ - task_submit(__self, (entry), (argument)); \ - } while (false) +#define GO(entry, argument) task_submit(__self, (entry), (argument)) struct task; +typedef struct { + struct task* task; +} task_t; + typedef uthread_routine task_body; void tasks_init(); @@ -25,7 +23,7 @@ void tasks_destroy(); void task_yield(struct task* caller); void task_exit(struct task* caller); -void task_submit(struct task* caller, uthread_routine entry, void* argument); +task_t task_submit(struct task* caller, uthread_routine entry, void* argument); #define TASK_DECLARE(name, type, argument) \ void task_body_##name(struct task* __self, type* argument); /* NOLINT */ \ diff --git a/source/coroed/sched/schedy.c b/source/coroed/sched/schedy.c index 773d36e..7d2bc81 100644 --- a/source/coroed/sched/schedy.c +++ b/source/coroed/sched/schedy.c @@ -187,12 +187,13 @@ void task_exit(struct task* caller) { task_yield(caller); } -void task_submit(struct task* caller, uthread_routine entry, void* argument) { +task_t task_submit(struct task* caller, uthread_routine entry, void* argument) { (void)caller; - sched_submit(*entry, argument); + task_t child = sched_submit(*entry, argument); + return child; } -void sched_submit(void (*entry)(), void* argument) { +task_t sched_submit(void (*entry)(), void* argument) { for (size_t i = 0; i < SCHED_THREADS_LIMIT; ++i) { struct task* task = &tasks[i]; @@ -218,7 +219,7 @@ void sched_submit(void (*entry)(), void* argument) { spinlock_unlock(&task->lock); if (is_submitted) { - return; + return (task_t){.task = task}; } } diff --git a/source/coroed/sched/schedy.h b/source/coroed/sched/schedy.h index eb2f676..9493a7f 100644 --- a/source/coroed/sched/schedy.h +++ b/source/coroed/sched/schedy.h @@ -1,12 +1,13 @@ #pragma once +#include "coroed/api/task.h" #include "uthread.h" struct task; void sched_init(); -void sched_submit(uthread_routine entry, void* argument); +task_t sched_submit(uthread_routine entry, void* argument); void sched_start();