mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-21 06:33:31 +00:00
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
This commit is contained in:
parent
356506a67a
commit
6d25ffc70b
@ -221,7 +221,7 @@ void Capability_map::remove(Cap_index *i)
|
||||
{
|
||||
using namespace Foc;
|
||||
|
||||
Lock_guard<Spin_lock> guard(_lock);
|
||||
Spin_lock::Guard guard(_lock);
|
||||
|
||||
if (i) {
|
||||
Core_cap_index* e = static_cast<Core_cap_index*>(_tree.first()
|
||||
|
@ -73,7 +73,7 @@ class Genode::Cap_index_allocator_tpl : public Cap_index_allocator
|
||||
|
||||
Cap_index* alloc_range(size_t cnt) override
|
||||
{
|
||||
Lock_guard<Spin_lock> 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<Spin_lock> 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<Spin_lock> guard(_lock);
|
||||
Spin_lock::Guard guard(_lock);
|
||||
|
||||
T *obj = static_cast<T*>(idx);
|
||||
for (size_t i = 0; i < cnt; obj++, i++) {
|
||||
|
@ -30,7 +30,6 @@
|
||||
/* Genode includes */
|
||||
#include <base/exception.h>
|
||||
#include <base/stdint.h>
|
||||
#include <base/lock_guard.h>
|
||||
#include <util/avl_tree.h>
|
||||
#include <util/noncopyable.h>
|
||||
#include <util/string.h>
|
||||
@ -162,7 +161,14 @@ class Genode::Spin_lock
|
||||
/**
|
||||
* Lock guard
|
||||
*/
|
||||
typedef Genode::Lock_guard<Spin_lock> Guard;
|
||||
struct Guard : Noncopyable
|
||||
{
|
||||
Spin_lock &_lock;
|
||||
|
||||
explicit Guard(Spin_lock &lock) : _lock(lock) { _lock.lock(); }
|
||||
|
||||
~Guard() { _lock.unlock(); }
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
@ -106,7 +106,7 @@ uint8_t Cap_index::dec()
|
||||
|
||||
Cap_index* Capability_map::find(Cap_index::id_t id)
|
||||
{
|
||||
Lock_guard<Spin_lock> 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<Spin_lock> 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<Spin_lock> 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<Spin_lock> guard(_lock);
|
||||
Spin_lock::Guard guard(_lock);
|
||||
|
||||
/* check whether capability id exists */
|
||||
Cap_index *i = _tree.first() ? _tree.first()->find_by_id(id) : 0;
|
||||
|
@ -20,7 +20,7 @@ using namespace Genode;
|
||||
|
||||
void Capability_map::remove(Genode::Cap_index* i)
|
||||
{
|
||||
Lock_guard<Spin_lock> guard(_lock);
|
||||
Spin_lock::Guard guard(_lock);
|
||||
|
||||
if (i) {
|
||||
Cap_index *e = _tree.first() ? _tree.first()->find_by_id(i->id()) : 0;
|
||||
|
@ -15,9 +15,6 @@
|
||||
#ifndef _CORE__SPEC__SMP__KERNEL__LOCK_H_
|
||||
#define _CORE__SPEC__SMP__KERNEL__LOCK_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/lock_guard.h>
|
||||
|
||||
namespace Kernel { class Lock; }
|
||||
|
||||
|
||||
@ -37,7 +34,14 @@ class Kernel::Lock
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
using Guard = Genode::Lock_guard<Lock>;
|
||||
struct Guard
|
||||
{
|
||||
Lock &_lock;
|
||||
|
||||
explicit Guard(Lock &lock) : _lock(lock) { _lock.lock(); }
|
||||
|
||||
~Guard() { _lock.unlock(); }
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* _CORE__SPEC__SMP__KERNEL__LOCK_H_ */
|
||||
|
@ -11,9 +11,6 @@
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/lock_guard.h>
|
||||
|
||||
/* core includes */
|
||||
#include <util.h>
|
||||
#include <platform_pd.h>
|
||||
|
@ -13,7 +13,6 @@
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/lock_guard.h>
|
||||
#include <util.h>
|
||||
#include <platform_pd.h>
|
||||
|
||||
|
@ -14,8 +14,6 @@
|
||||
#ifndef _INCLUDE__BASE__LOCK_H_
|
||||
#define _INCLUDE__BASE__LOCK_H_
|
||||
|
||||
#include <base/lock_guard.h>
|
||||
|
||||
namespace Genode {
|
||||
class Lock;
|
||||
class Thread;
|
||||
|
@ -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 <typename> 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 <typename LT>
|
||||
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_ */
|
Loading…
Reference in New Issue
Block a user