feat: use a single allocation per entry
This commit is contained in:
parent
0527449ed3
commit
a4cb6bcdba
@ -38,6 +38,7 @@ struct context_entry {
|
|||||||
void *waiting;
|
void *waiting;
|
||||||
void* retvalue;
|
void* retvalue;
|
||||||
int valgrind_id;
|
int valgrind_id;
|
||||||
|
char stack[STACK_SIZE];
|
||||||
char status;
|
char status;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ int thread_create(thread_t* newthread, void* (*func)(void*), void* funcarg)
|
|||||||
|
|
||||||
getcontext(&new_entry->context);
|
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_size = STACK_SIZE;
|
||||||
new_entry->context.uc_stack.ss_flags = 0;
|
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));
|
TRACE("DEBUG %p,%d", entry, WAS_ALLOCATED(entry));
|
||||||
if (WAS_ALLOCATED(entry)) {
|
if (WAS_ALLOCATED(entry)) {
|
||||||
VALGRIND_STACK_DEREGISTER(entry->valgrind_id);
|
VALGRIND_STACK_DEREGISTER(entry->valgrind_id);
|
||||||
free(entry->context.uc_stack.ss_sp);
|
|
||||||
}
|
}
|
||||||
free(entry);
|
free(entry);
|
||||||
|
|
||||||
@ -205,7 +205,6 @@ void clear_context(void)
|
|||||||
last = TAILQ_FIRST(&head);
|
last = TAILQ_FIRST(&head);
|
||||||
TAILQ_REMOVE(&head, last, link);
|
TAILQ_REMOVE(&head, 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);
|
||||||
}
|
}
|
||||||
if (IS_WAITED(last)) {
|
if (IS_WAITED(last)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user