diff --git a/repos/libports/src/lib/pthread/thread.cc b/repos/libports/src/lib/pthread/thread.cc index 91bd7dbca1..1ebd33c912 100644 --- a/repos/libports/src/lib/pthread/thread.cc +++ b/repos/libports/src/lib/pthread/thread.cc @@ -22,6 +22,8 @@ #include /* malloc, free */ #include "thread.h" +#include /* libc suspend/resume */ + using namespace Genode; /* @@ -60,6 +62,22 @@ static __attribute__((constructor)) Thread * main_thread() } +/* + * pthread + */ +void pthread::Thread_object::entry() +{ + void *exit_status = _start_routine(_arg); + _exiting = true; + Libc::resume_all(); + pthread_exit(exit_status); +} + + +/* + * Registry + */ + void Pthread_registry::insert(pthread_t thread) { /* prevent multiple insertions at the same location */ @@ -226,8 +244,7 @@ extern "C" { * of the pthread object would also destruct the 'Thread' of the main * thread. */ - static pthread_attr main_thread_attr; - static pthread *main = new pthread(*Thread::myself(), &main_thread_attr); + static pthread *main = new pthread(*Thread::myself()); return main; } @@ -276,7 +293,7 @@ extern "C" { if (!attr) return EINVAL; - *attr = pthread->attr(); + (*attr)->pthread = pthread; return 0; } diff --git a/repos/libports/src/lib/pthread/thread.h b/repos/libports/src/lib/pthread/thread.h index c283400566..ebb272ec4a 100644 --- a/repos/libports/src/lib/pthread/thread.h +++ b/repos/libports/src/lib/pthread/thread.h @@ -20,7 +20,6 @@ #include #include -#include /* * Used by 'pthread_self()' to find out if the current thread is an alien @@ -119,13 +118,7 @@ struct pthread : Genode::Noncopyable, Genode::Thread::Tls::Base _start_routine(start_routine), _arg(arg) { } - void entry() override - { - void *exit_status = _start_routine(_arg); - _exiting = true; - Libc::resume_all(); - pthread_exit(exit_status); - } + void entry() override; }; Genode::Constructible _thread_object; @@ -145,15 +138,9 @@ struct pthread : Genode::Noncopyable, Genode::Thread::Tls::Base */ Genode::Thread &_thread; - pthread_attr_t _attr; - void _associate_thread_with_pthread() { - if (_attr) - _attr->pthread = this; - Genode::Thread::Tls::Base::tls(_thread, *this); - pthread_registry().insert(this); } @@ -162,13 +149,12 @@ struct pthread : Genode::Noncopyable, Genode::Thread::Tls::Base /** * Constructor for threads created via 'pthread_create' */ - pthread(pthread_attr_t attr, start_routine_t start_routine, + pthread(start_routine_t start_routine, void *arg, size_t stack_size, char const * name, Genode::Cpu_session * cpu, Genode::Affinity::Location location) : _thread(_construct_thread_object(name, stack_size, cpu, location, - start_routine, arg)), - _attr(attr) + start_routine, arg)) { _associate_thread_with_pthread(); } @@ -177,10 +163,9 @@ struct pthread : Genode::Noncopyable, Genode::Thread::Tls::Base * Constructor to create pthread object out of existing thread, * i.e., the main thread */ - pthread(Genode::Thread &existing_thread, pthread_attr_t attr) + pthread(Genode::Thread &existing_thread) : - _thread(existing_thread), - _attr(attr) + _thread(existing_thread) { _associate_thread_with_pthread(); } @@ -200,8 +185,6 @@ struct pthread : Genode::Noncopyable, Genode::Thread::Tls::Base void *stack_top() const { return _thread.stack_top(); } void *stack_base() const { return _thread.stack_base(); } - - pthread_attr_t attr() { return _attr; } }; #endif /* _INCLUDE__SRC_LIB_PTHREAD_THREAD_H_ */ diff --git a/repos/libports/src/lib/pthread/thread_create.cc b/repos/libports/src/lib/pthread/thread_create.cc index 7daf425748..02f8eda109 100644 --- a/repos/libports/src/lib/pthread/thread_create.cc +++ b/repos/libports/src/lib/pthread/thread_create.cc @@ -33,9 +33,9 @@ extern "C" size_t const stack_size = (attr && *attr && (*attr)->stack_size) ? (*attr)->stack_size : STACK_SIZE; - pthread_t thread_obj = new pthread(attr ? *attr : 0, start_routine, - arg, stack_size, "pthread", nullptr, - Genode::Affinity::Location()); + pthread_t thread_obj = new pthread(start_routine, arg, stack_size, + "pthread", nullptr, + Genode::Affinity::Location()); if (!thread_obj) return EAGAIN;