From 7f1aa05f3e8ebe7d4c67653ae1068b9769f0c28a Mon Sep 17 00:00:00 2001 From: Alessandre Laguierce Date: Wed, 2 Apr 2025 15:24:30 +0200 Subject: [PATCH] feat: better scheduling for fibo --- Makefile | 2 +- src/thread/thread.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 982bba6..892dd42 100644 --- a/Makefile +++ b/Makefile @@ -109,7 +109,7 @@ ${check_targets}: check_%: ${build_dir}/% $^ ${check_argv} ${bins_target}: ${build_dir}/%: ${objs} ${build_dir}/${tst_dir}/%.o - ${CC} -o $@ $^ ${CFLAGS} ./lib/libmimalloc ${LDFLAGS} + ${CC} -o $@ $^ ${CFLAGS} ${LDFLAGS} ${build_dir}/libthread.so: ${objs} ${CC} -o $@ -shared $^ ${CFLAGS} ${LDFLAGS} diff --git a/src/thread/thread.c b/src/thread/thread.c index 994f558..028f234 100644 --- a/src/thread/thread.c +++ b/src/thread/thread.c @@ -17,7 +17,8 @@ #define IS_WAITING(entry) (entry->status & WAITING) #define GET_LAST_WAITED_THREAD(entry) (entry->last_waited ? entry->last_waited->last_thread : NULL) #define WAITED 0x8 -#define MUTEX_WAITING 0xf0 +#define YIELD (char) 0x20 +#define MUTEX_WAITING (char) 0x10 #define IS_WAITED(entry) (entry->status & WAITED) #define IS_MUTEX_WAITING(entry) (entry->status & MUTEX_WAITING) @@ -79,6 +80,10 @@ int thread_yield(void) if (TAILQ_EMPTY(&head)) { return 0; } + if (!(running->status & YIELD)) { + running->status |= YIELD; + return 0; + } /* Current strategy : * if we have checked the number of threads then keep the running one