sel4: use yielding spinlock for 'Genode::Lock'
This commit is contained in:
parent
f24b212e47
commit
41b99a6b51
56
repos/base-sel4/include/base/cancelable_lock.h
Normal file
56
repos/base-sel4/include/base/cancelable_lock.h
Normal 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_ */
|
|
@ -27,7 +27,6 @@ SRC_CC += thread/thread_bootstrap.cc
|
||||||
#SRC_CC += env/cap_map.cc
|
#SRC_CC += env/cap_map.cc
|
||||||
|
|
||||||
INC_DIR += $(REP_DIR)/src/base/lock
|
INC_DIR += $(REP_DIR)/src/base/lock
|
||||||
INC_DIR += $(BASE_DIR)/src/base/lock
|
|
||||||
INC_DIR += $(BASE_DIR)/src/base/thread
|
INC_DIR += $(BASE_DIR)/src/base/thread
|
||||||
|
|
||||||
vpath %.cc $(REP_DIR)/src/base
|
vpath %.cc $(REP_DIR)/src/base
|
||||||
|
|
44
repos/base-sel4/src/base/lock/lock.cc
Normal file
44
repos/base-sel4/src/base/lock/lock.cc
Normal 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;
|
||||||
|
}
|
|
@ -1,31 +1,21 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* \brief seL4-specific helper functions for the Lock implementation
|
* \brief seL4-specific helper functions for the Lock implementation
|
||||||
* \author Norman Feske
|
* \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
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
* under the terms of the GNU General Public License version 2.
|
* under the terms of the GNU General Public License version 2.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Genode includes */
|
/* seL4 includes */
|
||||||
#include <base/native_types.h>
|
#include <sel4/interfaces/sel4_client.h>
|
||||||
#include <base/thread.h>
|
|
||||||
|
|
||||||
|
|
||||||
static inline void thread_yield() { }
|
static inline void thread_yield() { seL4_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() { }
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user