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
This commit is contained in:
Norman Feske 2016-01-22 22:00:54 +01:00 committed by Christian Helmuth
parent 3473955212
commit 1a19ca5f7b
4 changed files with 6 additions and 118 deletions

View File

@ -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 <base/lock_guard.h>
#include <base/blocking.h>
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<Cancelable_lock> Guard;
};
}
#endif /* _INCLUDE__BASE__CANCELABLE_LOCK_H_ */

View File

@ -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;
}

View File

@ -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 <base/lock_guard.h>
#include <base/blocking.h>
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<Cancelable_lock> Guard;
};
}
#endif /* _INCLUDE__BASE__CANCELABLE_LOCK_H_ */

View File

@ -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;
}