pthread: remove 'pthread_attr' from pthread class

issue #2791
pthread_attr is not associated with any thread, the statistics must be
gathered at runtime, while 'pthread_attr_get_np' may retrieve attributes
by from any thread. Addtionally, the attributes given to
'pthread_create' will most likely be deleted after the creation call.
This commit is contained in:
Sebastian Sumpf 2018-01-11 18:24:59 +01:00 committed by Christian Helmuth
parent 2ff11dc063
commit b4209cb3bb
3 changed files with 28 additions and 28 deletions

View File

@ -22,6 +22,8 @@
#include <stdlib.h> /* malloc, free */
#include "thread.h"
#include <libc/task.h> /* 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;
}

View File

@ -20,7 +20,6 @@
#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
@ -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> _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_ */

View File

@ -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;