From 6d25ffc70bb16aa4fe5a2e83e4b271c96115632b Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 21 Feb 2023 16:35:23 +0100 Subject: [PATCH] Remove base/lock_guard.h For Genode API users, the 'Mutex::Guard' is the way to go. Special lock implementations can bring their own 'Guard' utilities. Fixes #4769 --- repos/base-foc/src/core/rpc_cap_factory.cc | 2 +- .../src/include/base/internal/cap_alloc.h | 6 +-- .../src/include/base/internal/cap_map.h | 10 ++++- repos/base-foc/src/lib/base/cap_map.cc | 8 ++-- repos/base-foc/src/lib/base/cap_map_remove.cc | 2 +- repos/base-hw/src/core/kernel/lock.h | 12 +++-- repos/base-okl4/src/core/platform_pd.cc | 3 -- repos/base-pistachio/src/core/platform_pd.cc | 1 - repos/base/include/base/lock.h | 2 - repos/base/include/base/lock_guard.h | 45 ------------------- 10 files changed, 25 insertions(+), 66 deletions(-) delete mode 100644 repos/base/include/base/lock_guard.h diff --git a/repos/base-foc/src/core/rpc_cap_factory.cc b/repos/base-foc/src/core/rpc_cap_factory.cc index 1474fe9407..afcb7b0dab 100644 --- a/repos/base-foc/src/core/rpc_cap_factory.cc +++ b/repos/base-foc/src/core/rpc_cap_factory.cc @@ -221,7 +221,7 @@ void Capability_map::remove(Cap_index *i) { using namespace Foc; - Lock_guard guard(_lock); + Spin_lock::Guard guard(_lock); if (i) { Core_cap_index* e = static_cast(_tree.first() diff --git a/repos/base-foc/src/include/base/internal/cap_alloc.h b/repos/base-foc/src/include/base/internal/cap_alloc.h index e45ef07224..076daa0134 100644 --- a/repos/base-foc/src/include/base/internal/cap_alloc.h +++ b/repos/base-foc/src/include/base/internal/cap_alloc.h @@ -73,7 +73,7 @@ class Genode::Cap_index_allocator_tpl : public Cap_index_allocator Cap_index* alloc_range(size_t cnt) override { - Lock_guard guard(_lock); + Spin_lock::Guard guard(_lock); /* * iterate through array and find unused, consecutive entries @@ -96,7 +96,7 @@ class Genode::Cap_index_allocator_tpl : public Cap_index_allocator Cap_index* alloc(addr_t addr) override { - Lock_guard guard(_lock); + Spin_lock::Guard guard(_lock); /* * construct the Cap_index pointer from the given @@ -114,7 +114,7 @@ class Genode::Cap_index_allocator_tpl : public Cap_index_allocator void free(Cap_index* idx, size_t cnt) override { - Lock_guard guard(_lock); + Spin_lock::Guard guard(_lock); T *obj = static_cast(idx); for (size_t i = 0; i < cnt; obj++, i++) { diff --git a/repos/base-foc/src/include/base/internal/cap_map.h b/repos/base-foc/src/include/base/internal/cap_map.h index 4653717f14..8c374cec6e 100644 --- a/repos/base-foc/src/include/base/internal/cap_map.h +++ b/repos/base-foc/src/include/base/internal/cap_map.h @@ -30,7 +30,6 @@ /* Genode includes */ #include #include -#include #include #include #include @@ -162,7 +161,14 @@ class Genode::Spin_lock /** * Lock guard */ - typedef Genode::Lock_guard Guard; + struct Guard : Noncopyable + { + Spin_lock &_lock; + + explicit Guard(Spin_lock &lock) : _lock(lock) { _lock.lock(); } + + ~Guard() { _lock.unlock(); } + }; }; diff --git a/repos/base-foc/src/lib/base/cap_map.cc b/repos/base-foc/src/lib/base/cap_map.cc index 9f79ed3534..f97b45766a 100644 --- a/repos/base-foc/src/lib/base/cap_map.cc +++ b/repos/base-foc/src/lib/base/cap_map.cc @@ -106,7 +106,7 @@ uint8_t Cap_index::dec() Cap_index* Capability_map::find(Cap_index::id_t id) { - Lock_guard guard(_lock); + Spin_lock::Guard guard(_lock); return _tree.first() ? _tree.first()->find_by_id(id) : 0; } @@ -114,7 +114,7 @@ Cap_index* Capability_map::find(Cap_index::id_t id) Cap_index* Capability_map::insert(Cap_index::id_t id) { - Lock_guard guard(_lock); + Spin_lock::Guard guard(_lock); ASSERT(!_tree.first() || !_tree.first()->find_by_id(id), "Double insertion in cap_map()!"); @@ -130,7 +130,7 @@ Cap_index* Capability_map::insert(Cap_index::id_t id) Cap_index* Capability_map::insert(Cap_index::id_t id, addr_t kcap) { - Lock_guard guard(_lock); + Spin_lock::Guard guard(_lock); /* remove potentially existent entry */ Cap_index *i = _tree.first() ? _tree.first()->find_by_id(id) : 0; @@ -150,7 +150,7 @@ Cap_index* Capability_map::insert_map(Cap_index::id_t id, addr_t kcap) { using namespace Foc; - Lock_guard guard(_lock); + Spin_lock::Guard guard(_lock); /* check whether capability id exists */ Cap_index *i = _tree.first() ? _tree.first()->find_by_id(id) : 0; diff --git a/repos/base-foc/src/lib/base/cap_map_remove.cc b/repos/base-foc/src/lib/base/cap_map_remove.cc index 6f404913f8..b7dc20ba8e 100644 --- a/repos/base-foc/src/lib/base/cap_map_remove.cc +++ b/repos/base-foc/src/lib/base/cap_map_remove.cc @@ -20,7 +20,7 @@ using namespace Genode; void Capability_map::remove(Genode::Cap_index* i) { - Lock_guard guard(_lock); + Spin_lock::Guard guard(_lock); if (i) { Cap_index *e = _tree.first() ? _tree.first()->find_by_id(i->id()) : 0; diff --git a/repos/base-hw/src/core/kernel/lock.h b/repos/base-hw/src/core/kernel/lock.h index 1befd37bac..60b542166b 100644 --- a/repos/base-hw/src/core/kernel/lock.h +++ b/repos/base-hw/src/core/kernel/lock.h @@ -15,9 +15,6 @@ #ifndef _CORE__SPEC__SMP__KERNEL__LOCK_H_ #define _CORE__SPEC__SMP__KERNEL__LOCK_H_ -/* Genode includes */ -#include - namespace Kernel { class Lock; } @@ -37,7 +34,14 @@ class Kernel::Lock void lock(); void unlock(); - using Guard = Genode::Lock_guard; + struct Guard + { + Lock &_lock; + + explicit Guard(Lock &lock) : _lock(lock) { _lock.lock(); } + + ~Guard() { _lock.unlock(); } + }; }; #endif /* _CORE__SPEC__SMP__KERNEL__LOCK_H_ */ diff --git a/repos/base-okl4/src/core/platform_pd.cc b/repos/base-okl4/src/core/platform_pd.cc index e7b6af7260..29928f31c4 100644 --- a/repos/base-okl4/src/core/platform_pd.cc +++ b/repos/base-okl4/src/core/platform_pd.cc @@ -11,9 +11,6 @@ * under the terms of the GNU Affero General Public License version 3. */ -/* Genode includes */ -#include - /* core includes */ #include #include diff --git a/repos/base-pistachio/src/core/platform_pd.cc b/repos/base-pistachio/src/core/platform_pd.cc index 21e91ea481..1305083880 100644 --- a/repos/base-pistachio/src/core/platform_pd.cc +++ b/repos/base-pistachio/src/core/platform_pd.cc @@ -13,7 +13,6 @@ */ /* Genode includes */ -#include #include #include diff --git a/repos/base/include/base/lock.h b/repos/base/include/base/lock.h index 003ab0dce6..10b1ff8688 100644 --- a/repos/base/include/base/lock.h +++ b/repos/base/include/base/lock.h @@ -14,8 +14,6 @@ #ifndef _INCLUDE__BASE__LOCK_H_ #define _INCLUDE__BASE__LOCK_H_ -#include - namespace Genode { class Lock; class Thread; diff --git a/repos/base/include/base/lock_guard.h b/repos/base/include/base/lock_guard.h deleted file mode 100644 index 364b0e1117..0000000000 --- a/repos/base/include/base/lock_guard.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * \brief Lock guard - * \author Norman Feske - * \date 2006-07-26 - */ - -/* - * Copyright (C) 2006-2017 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -#ifndef _INCLUDE__BASE__LOCK_GUARD_H_ -#define _INCLUDE__BASE__LOCK_GUARD_H_ - -namespace Genode { template class Lock_guard; } - - -/** - * Lock guard template - * - * \param LT lock type - * - * A lock guard is instantiated as a local variable. When a lock guard is - * constructed, it acquires the lock that is specified as constructor argument. - * When the control flow leaves the scope of the lock-guard variable via a - * return statement or an exception, the lock guard's destructor gets called, - * freeing the lock. - */ -template -class Genode::Lock_guard -{ - private: - - LT &_lock; - - public: - - explicit Lock_guard(LT &lock) : _lock(lock) { _lock.lock(); } - - ~Lock_guard() { _lock.unlock(); } -}; - -#endif /* _INCLUDE__BASE__LOCK_GUARD_H_ */