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/list.h>
#include <base/lock.h>
#include <base/mutex.h>
namespace Genode {
@ -52,7 +52,7 @@ class Genode::Registry_base
/**
* Protect '_reinsert_ptr'
*/
Lock _lock { };
Mutex _mutex { };
/*
* Assigned by 'Registry::_for_each'
@ -78,7 +78,7 @@ class Genode::Registry_base
protected:
Lock mutable _lock { }; /* protect '_elements' */
Mutex mutable _mutex { }; /* protect '_elements' */
List<Element> _elements { };
private:
@ -133,7 +133,7 @@ struct Genode::Registry : private Registry_base
template <typename FUNC>
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;
for ( ; e; e = next) {

View File

@ -28,7 +28,7 @@ Registry_base::Element::Element(Registry_base &registry, void *obj)
Registry_base::Element::~Element()
{
{
Lock::Guard guard(_lock);
Mutex::Guard guard(_mutex);
if (_notify_ptr && _registry._curr == this) {
/*
@ -43,7 +43,7 @@ Registry_base::Element::~Element()
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 destructor not before the registry lost the pointer to this
* 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)
{
Lock::Guard lock_guard(_lock);
Mutex::Guard guard(_mutex);
_elements.insert(&element);
}
@ -65,7 +65,7 @@ void Registry_base::_insert(Element &element)
void Registry_base::_remove(Element &element)
{
Lock::Guard lock_guard(_lock);
Mutex::Guard guard(_mutex);
_elements.remove(&element);
}
@ -82,7 +82,7 @@ Registry_base::Element *Registry_base::_processed(Notify &notify,
return at;
/* 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 */
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
* 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.
*/
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)
{
Lock::Guard lock_guard(_lock);
Mutex::Guard guard(_mutex);
/* insert position in list of processed elements */
Element *at = nullptr;
@ -118,7 +118,7 @@ void Registry_base::_for_each(Untyped_functor &functor)
Notify notify(Notify::Keep::KEEP, Thread::myself());
{
/* tell the element where to report its status */
Lock::Guard guard(e->_lock);
Mutex::Guard guard(e->_mutex);
_curr = e;
e->_notify_ptr = &notify;
}