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

@ -43,7 +43,7 @@ Rpc_exception_code Genode::ipc_call(Native_capability dst,
rcv_window.rcv_wnd(log2_max);
}
Nova::Utcb &utcb = *(Nova::Utcb *)Thread_base::myself()->utcb();
Nova::Utcb &utcb = *(Nova::Utcb *)Thread::myself()->utcb();
/* the protocol value is unused as the badge is delivered by the kernel */
if (!copy_msgbuf_to_utcb(utcb, snd_msg, 0)) {

View File

@ -83,7 +83,7 @@ void Rpc_entrypoint::_dissolve(Rpc_object_base *obj)
*/
using namespace Nova;
Utcb *utcb = reinterpret_cast<Utcb *>(Thread_base::myself()->utcb());
Utcb *utcb = reinterpret_cast<Utcb *>(Thread::myself()->utcb());
/* don't call ourself */
if (utcb == reinterpret_cast<Utcb *>(this->utcb()))
return;
@ -111,7 +111,7 @@ static void reply(Nova::Utcb &utcb, Rpc_exception_code exc, Msgbuf_base &snd_msg
{
copy_msgbuf_to_utcb(utcb, snd_msg, exc.value);
Nova::reply(Thread_base::myself()->stack_top());
Nova::reply(Thread::myself()->stack_top());
}
@ -124,8 +124,8 @@ void Rpc_entrypoint::_activation_entry()
addr_t id_pt; asm volatile ("" : "=a" (id_pt));
#endif
Rpc_entrypoint &ep = *static_cast<Rpc_entrypoint *>(Thread_base::myself());
Nova::Utcb &utcb = *(Nova::Utcb *)Thread_base::myself()->utcb();
Rpc_entrypoint &ep = *static_cast<Rpc_entrypoint *>(Thread::myself());
Nova::Utcb &utcb = *(Nova::Utcb *)Thread::myself()->utcb();
Receive_window &rcv_window = ep.native_thread().rcv_window;
rcv_window.post_ipc(utcb);
@ -219,7 +219,7 @@ Rpc_entrypoint::Rpc_entrypoint(Pd_session *pd_session, size_t stack_size,
const char *name, bool start_on_construction,
Affinity::Location location)
:
Thread_base(Cpu_session::DEFAULT_WEIGHT, name, stack_size, location),
Thread(Cpu_session::Weight::DEFAULT_WEIGHT, name, stack_size, location),
_delay_start(Lock::LOCKED),
_pd_session(*pd_session)
{
@ -228,7 +228,7 @@ Rpc_entrypoint::Rpc_entrypoint(Pd_session *pd_session, size_t stack_size,
native_thread().ec_sel = Native_thread::INVALID_INDEX - 1;
/* required to create a 'local' EC */
Thread_base::start();
Thread::start();
/* create cleanup portal */
_cap = _alloc_rpc_cap(_pd_session, Native_capability(native_thread().ec_sel),
@ -236,7 +236,7 @@ Rpc_entrypoint::Rpc_entrypoint(Pd_session *pd_session, size_t stack_size,
if (!_cap.valid())
throw Cpu_session::Thread_creation_failed();
Receive_window &rcv_window = Thread_base::native_thread().rcv_window;
Receive_window &rcv_window = Thread::native_thread().rcv_window;
/* prepare portal receive window of new thread */
if (!rcv_window.prepare_rcv_window(*(Nova::Utcb *)&_stack->utcb()))

View File

@ -27,7 +27,7 @@ void Genode::sleep_forever()
{
using namespace Nova;
Thread_base *myself = Thread_base::myself();
Thread *myself = Thread::myself();
addr_t sem = myself ? myself->native_thread().exc_pt_sel + SM_SEL_EC : SM_SEL_EC;
while (1) {

View File

@ -109,11 +109,11 @@ void prepare_reinit_main_thread()
}
/*****************
** Thread_base **
*****************/
/************
** Thread **
************/
Native_utcb *Thread_base::utcb()
Native_utcb *Thread::utcb()
{
/*
* If 'utcb' is called on the object returned by 'myself',

View File

@ -36,19 +36,17 @@ using namespace Genode;
/**
* Entry point entered by new threads
*/
void Thread_base::_thread_start()
void Thread::_thread_start()
{
using namespace Genode;
/* catch any exception at this point and try to print an error message */
try {
Thread_base::myself()->entry();
Thread::myself()->entry();
} catch (...) {
char thread_name[48];
Thread_base::myself()->name(thread_name, sizeof(thread_name));
try {
PERR("Thread '%s' died because of an uncaught exception", thread_name);
PERR("Thread '%s' died because of an uncaught exception",
Thread::myself()->name().string());
} catch (...) {
/* die in a noisy way */
nova_die();
@ -57,7 +55,7 @@ void Thread_base::_thread_start()
throw;
}
Thread_base::myself()->_join_lock.unlock();
Thread::myself()->_join_lock.unlock();
/* sleep silently */
Genode::sleep_forever();
@ -68,7 +66,7 @@ void Thread_base::_thread_start()
** Thread base **
*****************/
void Thread_base::_init_platform_thread(size_t weight, Type type)
void Thread::_init_platform_thread(size_t weight, Type type)
{
using namespace Nova;
@ -113,16 +111,14 @@ void Thread_base::_init_platform_thread(size_t weight, Type type)
_cpu_session = env()->cpu_session();
/* create thread at core */
char buf[48];
name(buf, sizeof(buf));
_thread_cap = _cpu_session->create_thread(env()->pd_session_cap(), weight, buf, _affinity);
_thread_cap = _cpu_session->create_thread(env()->pd_session_cap(), name(),
_affinity, Weight(weight));
if (!_thread_cap.valid())
throw Cpu_session::Thread_creation_failed();
}
void Thread_base::_deinit_platform_thread()
void Thread::_deinit_platform_thread()
{
using namespace Nova;
@ -139,7 +135,7 @@ void Thread_base::_deinit_platform_thread()
}
void Thread_base::start()
void Thread::start()
{
if (native_thread().ec_sel < Native_thread::INVALID_INDEX - 1)
throw Cpu_session::Thread_creation_failed();
@ -201,7 +197,7 @@ void Thread_base::start()
}
void Thread_base::cancel_blocking()
void Thread::cancel_blocking()
{
using namespace Nova;