Noux: add Io_receptor_registry

This commit is contained in:
Josef Söntgen 2012-10-24 18:31:24 +02:00
parent 082d8d6623
commit c74bdbf8d8
2 changed files with 90 additions and 0 deletions

View File

@ -30,6 +30,8 @@
#include <ram_session_component.h>
#include <cpu_session_component.h>
#include <child_policy.h>
#include <io_receptor_registry.h>
namespace Noux {
@ -72,6 +74,11 @@ namespace Noux {
class User_info;
User_info *user_info();
/**
* Return singleton instance of Io_receptor_registry
*/
Io_receptor_registry *io_receptor_registry();
class Child;
bool is_init_process(Child *child);

View File

@ -0,0 +1,83 @@
/*
* \brief Io receptor registry
* \author Josef Soentgen
* \date 2012-10-05
*/
/*
* Copyright (C) 2012 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _NOUX__IO_RECEPTOR_REGISTRY_H_
#define _NOUX__IO_RECEPTOR_REGISTRY_H_
/* Genode includes */
#include <base/lock.h>
#include <base/semaphore.h>
#include <util/list.h>
namespace Noux {
struct Io_receptor : List<Io_receptor>::Element
{
private:
Semaphore *_sem;
public:
Io_receptor(Semaphore *semaphore)
:
_sem(semaphore)
{ }
void check_and_wakeup()
{
if (_sem)
_sem->up();
}
};
class Io_receptor_registry
{
private:
List<Io_receptor> _receptors;
Lock _receptors_lock;
public:
Io_receptor_registry() { }
~Io_receptor_registry()
{
Io_receptor *receptor;
while ((receptor = _receptors.first()) != 0)
_receptors.remove(receptor);
}
void register_receptor(Io_receptor *receptor)
{
Lock::Guard guard(_receptors_lock);
_receptors.insert(receptor);
}
void unregister_receptor(Io_receptor *receptor)
{
Lock::Guard guard(_receptors_lock);
_receptors.remove(receptor);
}
Io_receptor *first() { return _receptors.first(); }
};
}
#endif /* _NOUX__IO_RECEPTOR_REGISTRY_H_ */