sel4: use yielding spinlock for 'Genode::Lock'

This commit is contained in:
Norman Feske 2015-05-07 14:22:42 +02:00 committed by Christian Helmuth
parent f24b212e47
commit 41b99a6b51
4 changed files with 108 additions and 19 deletions

View File

@ -0,0 +1,56 @@
/*
* \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

@ -27,7 +27,6 @@ SRC_CC += thread/thread_bootstrap.cc
#SRC_CC += env/cap_map.cc
INC_DIR += $(REP_DIR)/src/base/lock
INC_DIR += $(BASE_DIR)/src/base/lock
INC_DIR += $(BASE_DIR)/src/base/thread
vpath %.cc $(REP_DIR)/src/base

View File

@ -0,0 +1,44 @@
/*
* \brief Lock implementation
* \author Norman Feske
* \date 2007-10-15
*/
/*
* Copyright (C) 2007-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.
*/
/* Genode includes */
#include <base/cancelable_lock.h>
#include <cpu/atomic.h>
#include <cpu/memory_barrier.h>
/* seL4 includes */
#include <sel4/interfaces/sel4_client.h>
using namespace Genode;
Cancelable_lock::Cancelable_lock(Cancelable_lock::State initial)
: _lock(UNLOCKED)
{
if (initial == LOCKED)
lock();
}
void Cancelable_lock::lock()
{
while (!Genode::cmpxchg(&_lock, UNLOCKED, LOCKED))
seL4_Yield();
}
void Cancelable_lock::unlock()
{
Genode::memory_barrier();
_lock = UNLOCKED;
}

View File

@ -1,31 +1,21 @@
/*
* \brief seL4-specific helper functions for the Lock implementation
* \author Norman Feske
* \date 2014-10-14
* \date 2015-05-07
*
* Based on the lock implementation of base-fiasco/src/base/lock/.
*/
/*
* Copyright (C) 2014 Genode Labs GmbH
* Copyright (C) 2015 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.
*/
/* Genode includes */
#include <base/native_types.h>
#include <base/thread.h>
/* seL4 includes */
#include <sel4/interfaces/sel4_client.h>
static inline void thread_yield() { }
static inline bool thread_check_stopped_and_restart(Genode::Thread_base *)
{
return false;
}
static inline void thread_switch_to(Genode::Thread_base *thread_base) { }
static inline void thread_stop_myself() { }
static inline void thread_yield() { seL4_Yield(); }