lib: c: add pthread implementation
This commit is contained in:
31
lib/libc/pthread/thread/pthread_exit.c
Normal file
31
lib/libc/pthread/thread/pthread_exit.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "pthread.h"
|
||||
|
||||
#include <mango/handle.h>
|
||||
#include <mango/task.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
extern void pthread_exit(void *retval)
|
||||
{
|
||||
struct __pthread *self = pthread_self();
|
||||
if (!self) {
|
||||
/* TODO: abort(); */
|
||||
return;
|
||||
}
|
||||
|
||||
if (self->thr_flags & THREAD_DETACHED) {
|
||||
kern_handle_t task;
|
||||
kern_handle_t address_space;
|
||||
task_self(&task);
|
||||
task_get_address_space(task, &address_space);
|
||||
kern_handle_close(task);
|
||||
|
||||
__pthread_unmap_exit(
|
||||
address_space,
|
||||
self->thr_map_base,
|
||||
self->thr_map_size);
|
||||
} else {
|
||||
self->thr_result = retval;
|
||||
thread_exit();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user