base: use mutex in registry

Issue #3612
This commit is contained in:
Alexander Boettcher 2020-01-27 11:26:17 +01:00 committed by Christian Helmuth
parent 5440cd4b50
commit 5bbaa30655
2 changed files with 12 additions and 12 deletions

View File

@ -16,7 +16,7 @@
#include <util/interface.h> #include <util/interface.h>
#include <util/list.h> #include <util/list.h>
#include <base/lock.h> #include <base/mutex.h>
namespace Genode { namespace Genode {
@ -52,7 +52,7 @@ class Genode::Registry_base
/** /**
* Protect '_reinsert_ptr' * Protect '_reinsert_ptr'
*/ */
Lock _lock { }; Mutex _mutex { };
/* /*
* Assigned by 'Registry::_for_each' * Assigned by 'Registry::_for_each'
@ -78,7 +78,7 @@ class Genode::Registry_base
protected: protected:
Lock mutable _lock { }; /* protect '_elements' */ Mutex mutable _mutex { }; /* protect '_elements' */
List<Element> _elements { }; List<Element> _elements { };
private: private:
@ -133,7 +133,7 @@ struct Genode::Registry : private Registry_base
template <typename FUNC> template <typename FUNC>
void for_each(FUNC const &fn) const void for_each(FUNC const &fn) const
{ {
Lock::Guard lock_guard(_lock); Mutex::Guard guard(_mutex);
Registry_base::Element const *e = _elements.first(), *next = nullptr; Registry_base::Element const *e = _elements.first(), *next = nullptr;
for ( ; e; e = next) { for ( ; e; e = next) {

View File

@ -28,7 +28,7 @@ Registry_base::Element::Element(Registry_base &registry, void *obj)
Registry_base::Element::~Element() Registry_base::Element::~Element()
{ {
{ {
Lock::Guard guard(_lock); Mutex::Guard guard(_mutex);
if (_notify_ptr && _registry._curr == this) { if (_notify_ptr && _registry._curr == this) {
/* /*
@ -43,7 +43,7 @@ Registry_base::Element::~Element()
return; return;
/* /*
* We synchronize on the _lock of the _registry, by invoking * We synchronize on the _mutex of the _registry, by invoking
* the _remove method below. This ensures that the object leaves * the _remove method below. This ensures that the object leaves
* the destructor not before the registry lost the pointer to this * the destructor not before the registry lost the pointer to this
* object. The actual removal attempt will be ignored by the list * object. The actual removal attempt will be ignored by the list
@ -57,7 +57,7 @@ Registry_base::Element::~Element()
void Registry_base::_insert(Element &element) void Registry_base::_insert(Element &element)
{ {
Lock::Guard lock_guard(_lock); Mutex::Guard guard(_mutex);
_elements.insert(&element); _elements.insert(&element);
} }
@ -65,7 +65,7 @@ void Registry_base::_insert(Element &element)
void Registry_base::_remove(Element &element) void Registry_base::_remove(Element &element)
{ {
Lock::Guard lock_guard(_lock); Mutex::Guard guard(_mutex);
_elements.remove(&element); _elements.remove(&element);
} }
@ -82,7 +82,7 @@ Registry_base::Element *Registry_base::_processed(Notify &notify,
return at; return at;
/* make sure that the critical section of '~Element' is completed */ /* make sure that the critical section of '~Element' is completed */
Lock::Guard guard(e._lock); Mutex::Guard guard(e._mutex);
/* here we know that 'e' still exists */ /* here we know that 'e' still exists */
e._notify_ptr = nullptr; e._notify_ptr = nullptr;
@ -90,7 +90,7 @@ Registry_base::Element *Registry_base::_processed(Notify &notify,
/* /*
* If '~Element' was preempted between the condition check and the * If '~Element' was preempted between the condition check and the
* assignment of keep = DISCARD, the above check would miss the DISCARD * assignment of keep = DISCARD, the above check would miss the DISCARD
* flag. Now, with the acquired lock, we know that the 'keep' value is * flag. Now, with the acquired mutex, we know that the 'keep' value is
* up to date. * up to date.
*/ */
if (notify.keep == Notify::Keep::DISCARD) if (notify.keep == Notify::Keep::DISCARD)
@ -106,7 +106,7 @@ Registry_base::Element *Registry_base::_processed(Notify &notify,
void Registry_base::_for_each(Untyped_functor &functor) void Registry_base::_for_each(Untyped_functor &functor)
{ {
Lock::Guard lock_guard(_lock); Mutex::Guard guard(_mutex);
/* insert position in list of processed elements */ /* insert position in list of processed elements */
Element *at = nullptr; Element *at = nullptr;
@ -118,7 +118,7 @@ void Registry_base::_for_each(Untyped_functor &functor)
Notify notify(Notify::Keep::KEEP, Thread::myself()); Notify notify(Notify::Keep::KEEP, Thread::myself());
{ {
/* tell the element where to report its status */ /* tell the element where to report its status */
Lock::Guard guard(e->_lock); Mutex::Guard guard(e->_mutex);
_curr = e; _curr = e;
e->_notify_ptr = &notify; e->_notify_ptr = &notify;
} }