base-hw: no virtual functions in signaling

Besides simplifying the execution flow in the signaling module, this prepares
for the in-place translation of the signaling module to Ada in the context of
the Spunky project.

Ref #3308
This commit is contained in:
Martin Stein 2019-04-28 23:56:34 +02:00 committed by Christian Helmuth
parent 3cc7774fe4
commit 88043e144a
4 changed files with 64 additions and 104 deletions

View File

@ -13,6 +13,7 @@
/* core includes */
#include <kernel/signal_receiver.h>
#include <kernel/thread.h>
using namespace Kernel;
@ -30,6 +31,8 @@ void Signal_handler::cancel_waiting()
}
Signal_handler::Signal_handler(Thread &thread) : _thread { thread } { }
Signal_handler::~Signal_handler() { cancel_waiting(); }
@ -43,7 +46,10 @@ void Signal_context_killer::cancel_waiting()
}
Signal_context_killer::Signal_context_killer() : _context(nullptr) { }
Signal_context_killer::Signal_context_killer(Thread &thread)
:
_thread { thread }
{ }
Signal_context_killer::~Signal_context_killer() { cancel_waiting(); }
@ -88,7 +94,7 @@ void Signal_context::ack()
}
if (_killer) {
_killer->_context = 0;
_killer->_signal_context_kill_done();
_killer->_thread.signal_context_kill_done();
_killer = 0;
}
}
@ -110,14 +116,14 @@ int Signal_context::kill(Signal_context_killer * const k)
_killer = k;
_killed = 1;
_killer->_context = this;
_killer->_signal_context_kill_pending();
_killer->_thread.signal_context_kill_pending();
return 0;
}
Signal_context::~Signal_context()
{
if (_killer) { _killer->_signal_context_kill_failed(); }
if (_killer) { _killer->_thread.signal_context_kill_failed(); }
_receiver._context_destructed(this);
}
@ -164,7 +170,7 @@ void Signal_receiver::_listen()
_handlers.dequeue([&] (Signal_handler::Fifo_element &elem) {
auto const handler = &elem.object();
handler->_receiver = nullptr;
handler->_receive_signal(&data, sizeof(data));
handler->_thread.signal_receive_signal(&data, sizeof(data));
});
context->_delivered();
});
@ -193,7 +199,7 @@ int Signal_receiver::add_handler(Signal_handler * const h)
if (h->_receiver) { return -1; }
_handlers.enqueue(h->_handlers_fe);
h->_receiver = this;
h->_await_signal(this);
h->_thread.signal_wait_for_signal(this);
_listen();
return 0;
}

View File

@ -23,6 +23,8 @@
namespace Kernel
{
class Thread;
/**
* Ability to receive signals from signal receivers
*/
@ -59,36 +61,15 @@ class Kernel::Signal_handler
typedef Genode::Fifo_element<Signal_handler> Fifo_element;
Fifo_element _handlers_fe { *this };
Signal_receiver * _receiver { nullptr };
/**
* Let the handler block for signal receipt
*
* \param receiver the signal pool that the thread blocks for
*/
virtual void _await_signal(Signal_receiver * const receiver) = 0;
/**
* Signal delivery backend
*
* \param base signal-data base
* \param size signal-data size
*/
virtual void _receive_signal(void * const base, size_t const size) = 0;
protected:
/***************
** Accessors **
***************/
Signal_receiver * receiver() const { return _receiver; }
Thread &_thread;
Fifo_element _handlers_fe { *this };
Signal_receiver *_receiver { nullptr };
public:
Signal_handler() { }
virtual ~Signal_handler();
Signal_handler(Thread &thread);
~Signal_handler();
/**
* Stop waiting for a signal receiver
@ -108,35 +89,14 @@ class Kernel::Signal_context_killer
Signal_context_killer(Signal_context_killer const &);
Signal_context_killer &operator = (Signal_context_killer const &);
Signal_context * _context;
/**
* Notice that the kill operation is pending
*/
virtual void _signal_context_kill_pending() = 0;
/**
* Notice that pending kill operation is done
*/
virtual void _signal_context_kill_done() = 0;
/**
* Notice that pending kill operation failed
*/
virtual void _signal_context_kill_failed() = 0;
protected:
/***************
** Accessors **
***************/
Signal_context * context() const { return _context; }
Thread &_thread;
Signal_context *_context { nullptr };
public:
Signal_context_killer();
virtual ~Signal_context_killer();
Signal_context_killer(Thread &thread);
~Signal_context_killer();
/**
* Stop waiting for a signal context

View File

@ -142,14 +142,14 @@ void Thread_fault::print(Genode::Output &out) const
}
void Thread::_signal_context_kill_pending()
void Thread::signal_context_kill_pending()
{
assert(_state == ACTIVE);
_become_inactive(AWAITS_SIGNAL_CONTEXT_KILL);
}
void Thread::_signal_context_kill_done()
void Thread::signal_context_kill_done()
{
assert(_state == AWAITS_SIGNAL_CONTEXT_KILL);
user_arg_0(0);
@ -157,7 +157,7 @@ void Thread::_signal_context_kill_done()
}
void Thread::_signal_context_kill_failed()
void Thread::signal_context_kill_failed()
{
assert(_state == AWAITS_SIGNAL_CONTEXT_KILL);
user_arg_0(-1);
@ -165,14 +165,14 @@ void Thread::_signal_context_kill_failed()
}
void Thread::_await_signal(Signal_receiver * const receiver)
void Thread::signal_wait_for_signal(Signal_receiver * const receiver)
{
_become_inactive(AWAITS_SIGNAL);
_signal_receiver = receiver;
}
void Thread::_receive_signal(void * const base, size_t const size)
void Thread::signal_receive_signal(void * const base, size_t const size)
{
assert(_state == AWAITS_SIGNAL);
Genode::memcpy(utcb()->data(), base, size);
@ -354,12 +354,12 @@ void Thread::_cancel_blocking()
_ipc_node.cancel_waiting();
return;
case AWAITS_SIGNAL:
Signal_handler::cancel_waiting();
_signal_handler.cancel_waiting();
user_arg_0(-1);
_become_active();
return;
case AWAITS_SIGNAL_CONTEXT_KILL:
Signal_context_killer::cancel_waiting();
_signal_context_killer.cancel_waiting();
return;
case ACTIVE:
return;
@ -523,7 +523,7 @@ void Thread::_call_await_signal()
return;
}
/* register handler at the receiver */
if (r->add_handler(this)) {
if (r->add_handler(&_signal_handler)) {
Genode::raw("failed to register handler at signal receiver");
user_arg_0(-1);
return;
@ -544,7 +544,7 @@ void Thread::_call_pending_signal()
}
/* register handler at the receiver */
if (r->add_handler(this)) {
if (r->add_handler(&_signal_handler)) {
user_arg_0(-1);
return;
}
@ -623,7 +623,7 @@ void Thread::_call_kill_signal_context()
}
/* kill signal context */
if (c->kill(this)) {
if (c->kill(&_signal_context_killer)) {
Genode::raw("failed to kill signal context");
user_arg_0(-1);
return;

View File

@ -58,8 +58,7 @@ struct Kernel::Thread_fault
*/
class Kernel::Thread
:
public Kernel::Object, public Cpu_job, public Signal_context_killer,
public Signal_handler, private Timeout
public Kernel::Object, public Cpu_job, private Timeout
{
private:
@ -128,21 +127,23 @@ class Kernel::Thread
DEAD = 7,
};
void *_obj_id_ref_ptr[Genode::Msgbuf_base::MAX_CAPS_PER_MSG];
Ipc_node _ipc_node;
capid_t _ipc_capid { cap_id_invalid() };
size_t _ipc_rcv_caps { 0 };
Genode::Native_utcb *_utcb { nullptr };
Pd *_pd { nullptr };
Signal_context *_pager { nullptr };
Thread_fault _fault { };
State _state;
Signal_receiver *_signal_receiver;
char const *const _label;
capid_t _timeout_sigid { 0 };
bool _paused { false };
bool _cancel_next_await_signal { false };
bool const _core { false };
void *_obj_id_ref_ptr[Genode::Msgbuf_base::MAX_CAPS_PER_MSG];
Ipc_node _ipc_node;
capid_t _ipc_capid { cap_id_invalid() };
size_t _ipc_rcv_caps { 0 };
Genode::Native_utcb *_utcb { nullptr };
Pd *_pd { nullptr };
Signal_context *_pager { nullptr };
Thread_fault _fault { };
State _state;
Signal_handler _signal_handler { *this };
Signal_context_killer _signal_context_killer { *this };
Signal_receiver *_signal_receiver;
char const *const _label;
capid_t _timeout_sigid { 0 };
bool _paused { false };
bool _cancel_next_await_signal { false };
bool const _core { false };
Genode::Constructible<Tlb_invalidation> _tlb_invalidation {};
Genode::Constructible<Destroy> _destroy {};
@ -273,24 +274,6 @@ class Kernel::Thread
void _ipc_init(Genode::Native_utcb &utcb, Thread &callee);
/***************************
** Signal_context_killer **
***************************/
void _signal_context_kill_pending() override;
void _signal_context_kill_failed() override;
void _signal_context_kill_done() override;
/********************
** Signal_handler **
********************/
void _await_signal(Signal_receiver * const receiver) override;
void _receive_signal(void * const base, size_t const size) override;
public:
Genode::Align_at<Genode::Cpu::Context> regs;
@ -390,6 +373,17 @@ class Kernel::Thread
void ipc_copy_msg(Thread &sender) ;
/*************
** Signals **
*************/
void signal_context_kill_pending();
void signal_context_kill_failed();
void signal_context_kill_done();
void signal_wait_for_signal(Signal_receiver * const receiver);
void signal_receive_signal(void * const base, size_t const size);
/*************
** Cpu_job **
*************/