ladybird/Libraries/LibPthread/pthread.cpp
Andreas Kling 69efa3f630 Kernel+LibPthread: Implement pthread_join()
It's now possible to block until another thread in the same process has
exited. We can also retrieve its exit value, which is whatever value it
passed to pthread_exit(). :^)
2019-11-14 20:58:23 +01:00

30 lines
687 B
C++

#include <AK/StdLibExtras.h>
#include <Kernel/Syscall.h>
#include <pthread.h>
#include <unistd.h>
extern "C" {
int pthread_create(pthread_t* thread, pthread_attr_t* attributes, void* (*start_routine)(void*), void* argument_to_start_routine)
{
if (!thread)
return -EINVAL;
UNUSED_PARAM(attributes);
int rc = create_thread(start_routine, argument_to_start_routine);
if (rc < 0)
return rc;
*thread = rc;
return 0;
}
void pthread_exit(void* value_ptr)
{
exit_thread(value_ptr);
}
int pthread_join(pthread_t thread, void** exit_value_ptr)
{
int rc = syscall(SC_join_thread, thread, exit_value_ptr);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
}