lib: c: add pthread implementation
This commit is contained in:
31
lib/libc/pthread/thread/pthread_join.c
Normal file
31
lib/libc/pthread/thread/pthread_join.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "pthread.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/object.h>
|
||||
#include <mango/signal.h>
|
||||
#include <mango/task.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
int pthread_join(struct __pthread *thread, void **retval)
|
||||
{
|
||||
kern_wait_item_t wait;
|
||||
wait.w_handle = thread->thr_handle;
|
||||
wait.w_waitfor = THREAD_SIGNAL_STOPPED;
|
||||
wait.w_observed = 0;
|
||||
|
||||
kern_status_t status = kern_object_wait(&wait, 1);
|
||||
if (status != KERN_OK) {
|
||||
return __set_errno(EINVAL);
|
||||
}
|
||||
|
||||
if (retval) {
|
||||
*retval = thread->thr_result;
|
||||
}
|
||||
|
||||
kern_handle_close(thread->thr_handle);
|
||||
munmap(thread->thr_map_base, thread->thr_map_size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user