From 589c6551f79b119f1239563bda570e69444b2978 Mon Sep 17 00:00:00 2001 From: Alessandre Laguierce Date: Wed, 2 Apr 2025 19:28:42 +0200 Subject: [PATCH] revert: awful time on thor --- Makefile | 2 +- src/thread/thread.c | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 1c00b9c..982bba6 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} ./lib/libmimalloc ${LDFLAGS} ${build_dir}/libthread.so: ${objs} ${CC} -o $@ -shared $^ ${CFLAGS} ${LDFLAGS} diff --git a/src/thread/thread.c b/src/thread/thread.c index 55df11e..994f558 100644 --- a/src/thread/thread.c +++ b/src/thread/thread.c @@ -17,8 +17,7 @@ #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 YIELD (char) 0x20 -#define MUTEX_WAITING (char) 0x10 +#define MUTEX_WAITING 0xf0 #define IS_WAITED(entry) (entry->status & WAITED) #define IS_MUTEX_WAITING(entry) (entry->status & MUTEX_WAITING) @@ -48,6 +47,7 @@ struct context_entry { struct mutex_fifo_entry_t* mutex_fifo_entry; int valgrind_id; char status; + char stack[STACK_SIZE]; }; struct last_thread_t { @@ -79,10 +79,6 @@ int thread_yield(void) if (TAILQ_EMPTY(&head)) { return 0; } - if (!(running->status & YIELD) && !IS_FINISHED(running)) { - running->status |= YIELD; - return 0; - } /* Current strategy : * if we have checked the number of threads then keep the running one @@ -137,9 +133,9 @@ int thread_create(thread_t* newthread, void* (*func)(void*), void* funcarg) } else { TRACE("Allocating new entry"); new_entry = malloc(sizeof(*new_entry)); + memset(new_entry->stack, 0, STACK_SIZE); - new_entry->context.uc_stack.ss_sp = malloc(STACK_SIZE); - memset(new_entry->context.uc_stack.ss_sp, 0, STACK_SIZE); + new_entry->context.uc_stack.ss_sp = new_entry->stack; new_entry->context.uc_stack.ss_size = STACK_SIZE; new_entry->context.uc_stack.ss_flags = 0; @@ -261,7 +257,6 @@ int thread_join(thread_t thread, void** retval) DBG("ADDING (%p) TO FREED TAIL", entry); TAILQ_INSERT_TAIL(&context_to_freed, entry, link); } else { - free(entry->context.uc_stack.ss_sp); free(entry); } @@ -297,7 +292,6 @@ void clear_context(void) TAILQ_REMOVE(&head, last, link); free(last->mutex_fifo_entry); if (WAS_ALLOCATED(last)) { - free(last->context.uc_stack.ss_sp); VALGRIND_STACK_DEREGISTER(last->valgrind_id); } if (IS_WAITED(last)) { @@ -311,7 +305,6 @@ void clear_context(void) free(last->mutex_fifo_entry); TAILQ_REMOVE(&context_to_freed, last, link); if (WAS_ALLOCATED(last)) { - free(last->context.uc_stack.ss_sp); VALGRIND_STACK_DEREGISTER(last->valgrind_id); } free(last);