Example for a cell that voluntarily terminates after a period of time.

This commit is contained in:
Michael Mueller
2023-08-07 17:54:24 +02:00
parent 4ee2070573
commit b711e0d091
2 changed files with 38 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
TARGET = volatile_cell
SRC_CC = volatile_cell.cc
LIBS += base

View File

@@ -0,0 +1,35 @@
#include <base/component.h>
#include <base/env.h>
#include <timer_session/connection.h>
#include <base/log.h>
namespace Hoitaja_test {
class Volatile_cell;
}
class Hoitaja_test::Volatile_cell
{
private:
Genode::Env &_env;
Timer::Connection _timer{_env};
void _handle_timeout()
{
Genode::log("My time has come. Exiting ...");
_env.parent().exit(0);
}
Genode::Signal_handler<Volatile_cell> _timeout_handler{
_env.ep(), *this, &Volatile_cell::_handle_timeout};
public:
Volatile_cell(Genode::Env &env) : _env(env)
{
Genode::log("My affinity space is ", _env.cpu().affinity_space());
_timer.sigh(_timeout_handler);
_timer.trigger_once(30 * 1000 * 1000);
}
};
void Component::construct(Genode::Env &env) { static Hoitaja_test::Volatile_cell cell(env); }