From 1a19ca5f7b937023e7db661c2b840f74b59304be Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 22 Jan 2016 22:00:54 +0100 Subject: [PATCH] base-fiasco/sel4: unified cancelable_lock.h On seL4 and L4/Fiasco, we employ a simple yielding spinlock as lock implementation. Consequently these base platforms used to have a simplified header. However, since the regular cancelable_lock has all the member variables needed to implement a spinlock, we can simply use the generic header on those two platforms too, just leaving some other parts of the generic header unused. So at API level, the difference is not visible. Issue #1832 --- .../include/base/cancelable_lock.h | 56 ------------------- repos/base-fiasco/src/base/lock/lock.cc | 6 +- .../base-sel4/include/base/cancelable_lock.h | 56 ------------------- repos/base-sel4/src/base/lock/lock.cc | 6 +- 4 files changed, 6 insertions(+), 118 deletions(-) delete mode 100644 repos/base-fiasco/include/base/cancelable_lock.h delete mode 100644 repos/base-sel4/include/base/cancelable_lock.h diff --git a/repos/base-fiasco/include/base/cancelable_lock.h b/repos/base-fiasco/include/base/cancelable_lock.h deleted file mode 100644 index c684501da..000000000 --- a/repos/base-fiasco/include/base/cancelable_lock.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * \brief Basic locking primitive - * \author Norman Feske - * \date 2006-07-26 - */ - -/* - * Copyright (C) 2006-2013 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. - */ - -#ifndef _INCLUDE__BASE__CANCELABLE_LOCK_H_ -#define _INCLUDE__BASE__CANCELABLE_LOCK_H_ - -#include -#include - -namespace Genode { - - class Cancelable_lock - { - private: - - int volatile _lock; - - public: - - enum State { LOCKED, UNLOCKED }; - - /** - * Constructor - */ - explicit Cancelable_lock(State initial = UNLOCKED); - - /** - * Try to aquire lock an block while lock is not free - * - * This function may throw a Genode::Blocking_canceled exception. - */ - void lock(); - - /** - * Release lock - */ - void unlock(); - - /** - * Lock guard - */ - typedef Genode::Lock_guard Guard; - }; -} - -#endif /* _INCLUDE__BASE__CANCELABLE_LOCK_H_ */ diff --git a/repos/base-fiasco/src/base/lock/lock.cc b/repos/base-fiasco/src/base/lock/lock.cc index 8cb6036d9..4516e3fee 100644 --- a/repos/base-fiasco/src/base/lock/lock.cc +++ b/repos/base-fiasco/src/base/lock/lock.cc @@ -26,7 +26,7 @@ using namespace Genode; Cancelable_lock::Cancelable_lock(Cancelable_lock::State initial) -: _lock(UNLOCKED) +: _state(UNLOCKED), _owner(nullptr) { if (initial == LOCKED) lock(); @@ -39,7 +39,7 @@ void Cancelable_lock::lock() * XXX: How to notice cancel-blocking signals issued when being outside the * 'l4_ipc_sleep' system call? */ - while (!Genode::cmpxchg(&_lock, UNLOCKED, LOCKED)) + while (!Genode::cmpxchg(&_state, UNLOCKED, LOCKED)) if (Fiasco::l4_ipc_sleep(Fiasco::l4_ipc_timeout(0, 0, 500, 0)) != L4_IPC_RETIMEOUT) throw Genode::Blocking_canceled(); } @@ -48,5 +48,5 @@ void Cancelable_lock::lock() void Cancelable_lock::unlock() { Genode::memory_barrier(); - _lock = UNLOCKED; + _state = UNLOCKED; } diff --git a/repos/base-sel4/include/base/cancelable_lock.h b/repos/base-sel4/include/base/cancelable_lock.h deleted file mode 100644 index c684501da..000000000 --- a/repos/base-sel4/include/base/cancelable_lock.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * \brief Basic locking primitive - * \author Norman Feske - * \date 2006-07-26 - */ - -/* - * Copyright (C) 2006-2013 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. - */ - -#ifndef _INCLUDE__BASE__CANCELABLE_LOCK_H_ -#define _INCLUDE__BASE__CANCELABLE_LOCK_H_ - -#include -#include - -namespace Genode { - - class Cancelable_lock - { - private: - - int volatile _lock; - - public: - - enum State { LOCKED, UNLOCKED }; - - /** - * Constructor - */ - explicit Cancelable_lock(State initial = UNLOCKED); - - /** - * Try to aquire lock an block while lock is not free - * - * This function may throw a Genode::Blocking_canceled exception. - */ - void lock(); - - /** - * Release lock - */ - void unlock(); - - /** - * Lock guard - */ - typedef Genode::Lock_guard Guard; - }; -} - -#endif /* _INCLUDE__BASE__CANCELABLE_LOCK_H_ */ diff --git a/repos/base-sel4/src/base/lock/lock.cc b/repos/base-sel4/src/base/lock/lock.cc index 6db20e817..45fe97c53 100644 --- a/repos/base-sel4/src/base/lock/lock.cc +++ b/repos/base-sel4/src/base/lock/lock.cc @@ -23,7 +23,7 @@ using namespace Genode; Cancelable_lock::Cancelable_lock(Cancelable_lock::State initial) -: _lock(UNLOCKED) +: _state(UNLOCKED), _owner(nullptr) { if (initial == LOCKED) lock(); @@ -32,7 +32,7 @@ Cancelable_lock::Cancelable_lock(Cancelable_lock::State initial) void Cancelable_lock::lock() { - while (!Genode::cmpxchg(&_lock, UNLOCKED, LOCKED)) + while (!Genode::cmpxchg(&_state, UNLOCKED, LOCKED)) seL4_Yield(); } @@ -40,5 +40,5 @@ void Cancelable_lock::lock() void Cancelable_lock::unlock() { Genode::memory_barrier(); - _lock = UNLOCKED; + _state = UNLOCKED; }