Add spin lock to DDE Kit

Linux DDE used to implement Linux spin locks based on 'dde_kit_lock'.
This works fine if a spin lock is initialized only once and used
infinitely. But if spin locks are initialized on-the-fly at a high rate,
each initialization causes the allocation of a new 'dde_kit_lock'.
Because in contrast to normal locks, spinlocks cannot be explicitly
destroyed, the spin-lock emulating locks are never freed. To solve the
leakage of locks, there seems to be no other way than to support the
semantics as expected by the Linux drivers. Hence, this patch introduces
a DDE Kit API for spin locks.
This commit is contained in:
Norman Feske
2012-01-27 02:01:07 +01:00
parent a107c89a8e
commit 48ac5143a2
3 changed files with 108 additions and 1 deletions

View File

@ -0,0 +1,57 @@
/*
* \brief Spin lock
* \author Norman Feske
* \date 2012-01-27
*/
/*
* 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.
*/
#include <base/env.h>
#include <cpu/atomic.h>
#include <base/printf.h>
extern "C" {
#include <dde_kit/spin_lock.h>
}
static inline void spinlock_lock(volatile int *lock_variable)
{
while (!Genode::cmpxchg(lock_variable, DDE_KIT_SPIN_LOCK_UNLOCKED,
DDE_KIT_SPIN_LOCK_LOCKED));
}
extern "C" void dde_kit_spin_lock_init(dde_kit_spin_lock *spin_lock)
{
*spin_lock = DDE_KIT_SPIN_LOCK_UNLOCKED;
}
extern "C" void dde_kit_spin_lock_lock(dde_kit_spin_lock *spin_lock)
{
spinlock_lock(spin_lock);
}
extern "C" int dde_kit_spin_lock_try_lock(dde_kit_spin_lock *spin_lock)
{
PERR("not implemented - will potentially block");
spinlock_lock(spin_lock);
/* success */
return 0;
}
extern "C" void dde_kit_spin_lock_unlock(dde_kit_spin_lock *spin_lock)
{
*spin_lock = DDE_KIT_SPIN_LOCK_UNLOCKED;
}