Thread API cleanup

This patch cleans up the thread API and comes with the following
noteworthy changes:

- Introduced Cpu_session::Weight type that replaces a formerly used
  plain integer value to prevent the accidental mix-up of
  arguments.
- The enum definition of Cpu_session::DEFAULT_WEIGHT moved to
  Cpu_session::Weight::DEFAULT_WEIGHT
- New Thread constructor that takes a 'Env &' as first argument.
  The original constructors are now marked as deprecated. For the
  common use case where the default 'Weight' and 'Affinity' are
  used, a shortcut is provided. In the long term, those two
  constructors should be the only ones to remain.
- The former 'Thread<>' class template has been renamed to
  'Thread_deprecated'.
- The former 'Thread_base' class is now called 'Thread'.
- The new 'name()' accessor returns the thread's name as 'Name'
  object as centrally defined via 'Cpu_session::Name'. It is meant to
  replace the old-fashioned 'name' method that takes a buffer and size
  as arguments.
- Adaptation of the thread test to the new API

Issue #1954
This commit is contained in:
Norman Feske
2016-05-04 12:27:17 +02:00
committed by Christian Helmuth
parent 7b73d1d823
commit fd401bdf53
211 changed files with 980 additions and 843 deletions

View File

@ -37,7 +37,7 @@ Child::Process::Initial_thread::Initial_thread(Cpu_session &cpu,
char const *name)
:
cpu(cpu),
cap(cpu.create_thread(pd, Cpu_session::DEFAULT_WEIGHT, name))
cap(cpu.create_thread(pd, name, Affinity::Location(), Cpu_session::Weight()))
{ }

View File

@ -431,7 +431,7 @@ Genode::Rpc_request Genode::ipc_reply_wait(Reply_capability const &last_caller,
* Block infinitely if called from the main thread. This may happen if the
* main thread calls 'sleep_forever()'.
*/
if (!Thread_base::myself()) {
if (!Thread::myself()) {
struct timespec ts = { 1000, 0 };
for (;;) lx_nanosleep(&ts, 0);
}
@ -443,7 +443,7 @@ Genode::Rpc_request Genode::ipc_reply_wait(Reply_capability const &last_caller,
msg.accept_sockets(Message::MAX_SDS_PER_MSG);
Native_thread &native_thread = Thread_base::myself()->native_thread();
Native_thread &native_thread = Thread::myself()->native_thread();
request_msg.reset();
int const ret = lx_recvmsg(native_thread.socket_pair.server_sd, msg.msg(), 0);
@ -479,10 +479,10 @@ Ipc_server::Ipc_server()
* definition, main is never an RPC entrypoint. However, the main thread
* may call 'sleep_forever()', which instantiates 'Ipc_server'.
*/
if (!Thread_base::myself())
if (!Thread::myself())
return;
Native_thread &native_thread = Thread_base::myself()->native_thread();
Native_thread &native_thread = Thread::myself()->native_thread();
if (native_thread.is_ipc_server) {
PRAW("[%d] unexpected multiple instantiation of Ipc_server by one thread",
@ -504,14 +504,14 @@ Ipc_server::Ipc_server()
Ipc_server::~Ipc_server()
{
if (!Thread_base::myself())
if (!Thread::myself())
return;
/*
* Reset thread role to non-server such that we can enter 'sleep_forever'
* without getting a warning.
*/
Native_thread &native_thread = Thread_base::myself()->native_thread();
Native_thread &native_thread = Thread::myself()->native_thread();
Genode::ep_sd_registry()->disassociate(native_thread.socket_pair.client_sd);
native_thread.is_ipc_server = false;

View File

@ -175,7 +175,7 @@ namespace Genode {
Socket_pair socket_pair;
Thread_base *thread = Thread_base::myself();
Thread *thread = Thread::myself();
if (thread) {
socket_pair.server_sd = native_cpu.server_sd(thread->cap()).dst().socket;
socket_pair.client_sd = native_cpu.client_sd(thread->cap()).dst().socket;

View File

@ -47,7 +47,7 @@ static void thread_exit_signal_handler(int) { lx_exit(0); }
static char signal_stack[0x2000] __attribute__((aligned(0x1000)));
void Thread_base::_thread_start()
void Thread::_thread_start()
{
lx_sigaltstack(signal_stack, sizeof(signal_stack));
@ -57,7 +57,7 @@ void Thread_base::_thread_start()
*/
lx_sigaction(LX_SIGUSR1, empty_signal_handler);
Thread_base * const thread = Thread_base::myself();
Thread * const thread = Thread::myself();
/* inform core about the new thread and process ID of the new thread */
Linux_native_cpu_client native_cpu(thread->_cpu_session->native_cpu());
@ -75,7 +75,7 @@ void Thread_base::_thread_start()
}
void Thread_base::_init_platform_thread(size_t weight, Type type)
void Thread::_init_platform_thread(size_t weight, Type type)
{
/* if no cpu session is given, use it from the environment */
if (!_cpu_session)
@ -84,7 +84,9 @@ void Thread_base::_init_platform_thread(size_t weight, Type type)
/* for normal threads create an object at the CPU session */
if (type == NORMAL) {
_thread_cap = _cpu_session->create_thread(env()->pd_session_cap(),
weight, _stack->name().string());
_stack->name().string(),
Affinity::Location(),
Weight());
return;
}
/* adjust initial object state for main threads */
@ -93,7 +95,7 @@ void Thread_base::_init_platform_thread(size_t weight, Type type)
}
void Thread_base::_deinit_platform_thread()
void Thread::_deinit_platform_thread()
{
/*
* Kill thread until it is really really dead
@ -124,7 +126,7 @@ void Thread_base::_deinit_platform_thread()
}
void Thread_base::start()
void Thread::start()
{
/* synchronize calls of the 'start' function */
static Lock lock;
@ -142,7 +144,7 @@ void Thread_base::start()
threadlib_initialized = true;
}
native_thread().tid = lx_create_thread(Thread_base::_thread_start, stack_top(), this);
native_thread().tid = lx_create_thread(Thread::_thread_start, stack_top(), this);
native_thread().pid = lx_getpid();
/* wait until the 'thread_start' function got entered */
@ -150,7 +152,7 @@ void Thread_base::start()
}
void Thread_base::cancel_blocking()
void Thread::cancel_blocking()
{
_cpu_session->cancel_blocking(_thread_cap);
}