From a4cb6bcdba6c36140b145fd5c9a024f318776722 Mon Sep 17 00:00:00 2001 From: Alessandre Laguierce Date: Sun, 23 Mar 2025 20:19:23 +0100 Subject: [PATCH] feat: use a single allocation per entry --- src/thread/thread.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/thread/thread.c b/src/thread/thread.c index e678e05..b378468 100644 --- a/src/thread/thread.c +++ b/src/thread/thread.c @@ -38,6 +38,7 @@ struct context_entry { void *waiting; void* retvalue; int valgrind_id; + char stack[STACK_SIZE]; char status; }; @@ -106,7 +107,7 @@ int thread_create(thread_t* newthread, void* (*func)(void*), void* funcarg) getcontext(&new_entry->context); - new_entry->context.uc_stack.ss_sp = malloc(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; @@ -167,7 +168,6 @@ int thread_join(thread_t thread, void** retval) TRACE("DEBUG %p,%d", entry, WAS_ALLOCATED(entry)); if (WAS_ALLOCATED(entry)) { VALGRIND_STACK_DEREGISTER(entry->valgrind_id); - free(entry->context.uc_stack.ss_sp); } free(entry); @@ -205,7 +205,6 @@ void clear_context(void) last = TAILQ_FIRST(&head); TAILQ_REMOVE(&head, last, link); if (WAS_ALLOCATED(last)) { - free(last->context.uc_stack.ss_sp); VALGRIND_STACK_DEREGISTER(last->valgrind_id); } if (IS_WAITED(last)) {