pthread: 'phtread_join'

issue #2791
This commit is contained in:
Sebastian Sumpf 2017-08-08 14:10:18 +02:00 committed by Christian Helmuth
parent 8605e15b4f
commit dfc2e2bd68
3 changed files with 32 additions and 0 deletions

View File

@ -3,6 +3,8 @@ SRC_CC = semaphore.cc rwlock.cc \
LIBS += libc
INC_DIR += $(REP_DIR)/src/lib
vpath % $(REP_DIR)/src/lib/pthread
SHARED_LIB = yes

View File

@ -111,6 +111,26 @@ extern "C" {
/* Thread */
int pthread_join(pthread_t thread, void **retval)
{
struct Check : Libc::Suspend_functor
{
bool suspend() override {
return true;
}
} check;
while (!thread->exiting()) {
Libc::suspend(check);
}
thread->join();
*((int **)retval) = 0;
return 0;
}
int pthread_attr_init(pthread_attr_t *attr)
{

View File

@ -20,6 +20,7 @@
#include <util/reconstructible.h>
#include <pthread.h>
#include <libc/task.h>
/*
* Used by 'pthread_self()' to find out if the current thread is an alien
@ -105,6 +106,7 @@ struct pthread : Genode::Noncopyable, Genode::Thread::Tls::Base
{
start_routine_t _start_routine;
void *_arg;
bool _exiting = false;
enum { WEIGHT = Genode::Cpu_session::Weight::DEFAULT_WEIGHT };
@ -120,6 +122,8 @@ struct pthread : Genode::Noncopyable, Genode::Thread::Tls::Base
void entry() override
{
void *exit_status = _start_routine(_arg);
_exiting = true;
Libc::resume_all();
pthread_exit(exit_status);
}
};
@ -187,6 +191,12 @@ struct pthread : Genode::Noncopyable, Genode::Thread::Tls::Base
}
void start() { _thread.start(); }
bool exiting() const
{
return _thread_object->_exiting;
}
void join() { _thread.join(); }
void *stack_top() const { return _thread.stack_top(); }
void *stack_base() const { return _thread.stack_base(); }