fix: valgrind for deadlocking
This commit is contained in:
parent
f6b199d601
commit
16a02f00ab
@ -182,7 +182,6 @@ int thread_join(thread_t thread, void** retval)
|
|||||||
running->last_waited = malloc(sizeof(struct last_thread_t));
|
running->last_waited = malloc(sizeof(struct last_thread_t));
|
||||||
running->last_waited->ref = 0 ;
|
running->last_waited->ref = 0 ;
|
||||||
entry->last_waited = running->last_waited;
|
entry->last_waited = running->last_waited;
|
||||||
entry->last_waited->ref++;
|
|
||||||
running->last_waited->last_thread = entry;
|
running->last_waited->last_thread = entry;
|
||||||
}
|
}
|
||||||
running->last_waited->ref++;
|
running->last_waited->ref++;
|
||||||
@ -207,6 +206,15 @@ int thread_join(thread_t thread, void** retval)
|
|||||||
} while (!IS_FINISHED(entry));
|
} while (!IS_FINISHED(entry));
|
||||||
// Exit from waiting state
|
// Exit from waiting state
|
||||||
running->status &= ~WAITING;
|
running->status &= ~WAITING;
|
||||||
|
|
||||||
|
if (running->last_waited) {
|
||||||
|
// Release the last waited thread if no one use it anymore
|
||||||
|
DBG("Last waited ref : %d", running->last_waited->ref);
|
||||||
|
if (--running->last_waited->ref == 0) {
|
||||||
|
free(running->last_waited);
|
||||||
|
}
|
||||||
|
running->last_waited = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save returned value if needed
|
// Save returned value if needed
|
||||||
@ -229,16 +237,6 @@ void thread_exit(void* retval)
|
|||||||
TRACE("Exit thread %p", running);
|
TRACE("Exit thread %p", running);
|
||||||
print_entry(running);
|
print_entry(running);
|
||||||
|
|
||||||
// free the memory of the last thread struct if no one use it anymore
|
|
||||||
if(running->last_waited) {
|
|
||||||
DBG("Last waited ref : %d", running->last_waited->ref);
|
|
||||||
if(--running->last_waited->ref == 0)
|
|
||||||
free(running->last_waited);
|
|
||||||
}
|
|
||||||
if (running == NULL) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
running->status |= FINISHED;
|
running->status |= FINISHED;
|
||||||
if (IS_WAITED(running)) {
|
if (IS_WAITED(running)) {
|
||||||
// If the thread was waited by another thread, we need to wake it up.
|
// If the thread was waited by another thread, we need to wake it up.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user