diff --git a/ports/src/noux/child.h b/ports/src/noux/child.h index 0d326b678..f87137a52 100644 --- a/ports/src/noux/child.h +++ b/ports/src/noux/child.h @@ -30,6 +30,8 @@ #include #include #include +#include + 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); diff --git a/ports/src/noux/io_receptor_registry.h b/ports/src/noux/io_receptor_registry.h new file mode 100644 index 000000000..79cba15e0 --- /dev/null +++ b/ports/src/noux/io_receptor_registry.h @@ -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 +#include +#include + + +namespace Noux { + + struct Io_receptor : List::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 _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_ */