revert: awful time on thor

This commit is contained in:
Alessandre Laguierce 2025-04-02 19:28:42 +02:00
parent f6b03da814
commit 589c6551f7
2 changed files with 5 additions and 12 deletions

View File

@ -109,7 +109,7 @@ ${check_targets}: check_%: ${build_dir}/%
$^ ${check_argv} $^ ${check_argv}
${bins_target}: ${build_dir}/%: ${objs} ${build_dir}/${tst_dir}/%.o ${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} ${build_dir}/libthread.so: ${objs}
${CC} -o $@ -shared $^ ${CFLAGS} ${LDFLAGS} ${CC} -o $@ -shared $^ ${CFLAGS} ${LDFLAGS}

View File

@ -17,8 +17,7 @@
#define IS_WAITING(entry) (entry->status & WAITING) #define IS_WAITING(entry) (entry->status & WAITING)
#define GET_LAST_WAITED_THREAD(entry) (entry->last_waited ? entry->last_waited->last_thread : NULL) #define GET_LAST_WAITED_THREAD(entry) (entry->last_waited ? entry->last_waited->last_thread : NULL)
#define WAITED 0x8 #define WAITED 0x8
#define YIELD (char) 0x20 #define MUTEX_WAITING 0xf0
#define MUTEX_WAITING (char) 0x10
#define IS_WAITED(entry) (entry->status & WAITED) #define IS_WAITED(entry) (entry->status & WAITED)
#define IS_MUTEX_WAITING(entry) (entry->status & MUTEX_WAITING) #define IS_MUTEX_WAITING(entry) (entry->status & MUTEX_WAITING)
@ -48,6 +47,7 @@ struct context_entry {
struct mutex_fifo_entry_t* mutex_fifo_entry; struct mutex_fifo_entry_t* mutex_fifo_entry;
int valgrind_id; int valgrind_id;
char status; char status;
char stack[STACK_SIZE];
}; };
struct last_thread_t { struct last_thread_t {
@ -79,10 +79,6 @@ int thread_yield(void)
if (TAILQ_EMPTY(&head)) { if (TAILQ_EMPTY(&head)) {
return 0; return 0;
} }
if (!(running->status & YIELD) && !IS_FINISHED(running)) {
running->status |= YIELD;
return 0;
}
/* Current strategy : /* Current strategy :
* if we have checked the number of threads then keep the running one * 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 { } else {
TRACE("Allocating new entry"); TRACE("Allocating new entry");
new_entry = malloc(sizeof(*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); new_entry->context.uc_stack.ss_sp = new_entry->stack;
memset(new_entry->context.uc_stack.ss_sp, 0, STACK_SIZE);
new_entry->context.uc_stack.ss_size = STACK_SIZE; new_entry->context.uc_stack.ss_size = STACK_SIZE;
new_entry->context.uc_stack.ss_flags = 0; 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); DBG("ADDING (%p) TO FREED TAIL", entry);
TAILQ_INSERT_TAIL(&context_to_freed, entry, link); TAILQ_INSERT_TAIL(&context_to_freed, entry, link);
} else { } else {
free(entry->context.uc_stack.ss_sp);
free(entry); free(entry);
} }
@ -297,7 +292,6 @@ void clear_context(void)
TAILQ_REMOVE(&head, last, link); TAILQ_REMOVE(&head, last, link);
free(last->mutex_fifo_entry); free(last->mutex_fifo_entry);
if (WAS_ALLOCATED(last)) { if (WAS_ALLOCATED(last)) {
free(last->context.uc_stack.ss_sp);
VALGRIND_STACK_DEREGISTER(last->valgrind_id); VALGRIND_STACK_DEREGISTER(last->valgrind_id);
} }
if (IS_WAITED(last)) { if (IS_WAITED(last)) {
@ -311,7 +305,6 @@ void clear_context(void)
free(last->mutex_fifo_entry); free(last->mutex_fifo_entry);
TAILQ_REMOVE(&context_to_freed, last, link); TAILQ_REMOVE(&context_to_freed, last, link);
if (WAS_ALLOCATED(last)) { if (WAS_ALLOCATED(last)) {
free(last->context.uc_stack.ss_sp);
VALGRIND_STACK_DEREGISTER(last->valgrind_id); VALGRIND_STACK_DEREGISTER(last->valgrind_id);
} }
free(last); free(last);