Browse Source

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
devel
Norman Feske 7 years ago committed by Christian Helmuth
parent
commit
1a19ca5f7b
  1. 56
      repos/base-fiasco/include/base/cancelable_lock.h
  2. 6
      repos/base-fiasco/src/base/lock/lock.cc
  3. 56
      repos/base-sel4/include/base/cancelable_lock.h
  4. 6
      repos/base-sel4/src/base/lock/lock.cc

56
repos/base-fiasco/include/base/cancelable_lock.h

@ -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_ */

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

56
repos/base-sel4/include/base/cancelable_lock.h

@ -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_ */

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

Loading…
Cancel
Save