Skip to content

Commit

Permalink
submit returns task
Browse files Browse the repository at this point in the history
  • Loading branch information
vityaman committed Nov 21, 2024
1 parent 449e4d2 commit 2b7e290
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
16 changes: 7 additions & 9 deletions source/coroed/api/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 */ \
Expand Down
9 changes: 5 additions & 4 deletions source/coroed/sched/schedy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -218,7 +219,7 @@ void sched_submit(void (*entry)(), void* argument) {

spinlock_unlock(&task->lock);
if (is_submitted) {
return;
return (task_t){.task = task};
}
}

Expand Down
3 changes: 2 additions & 1 deletion source/coroed/sched/schedy.h
Original file line number Diff line number Diff line change
@@ -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();

Expand Down

0 comments on commit 2b7e290

Please sign in to comment.