2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Fiasco.OC-specific helper functions for the Lock implementation
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2011-02-22
|
|
|
|
*
|
|
|
|
* This file serves as adapter between the generic lock implementation
|
|
|
|
* in 'lock.cc' and the underlying kernel.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2011-2013 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
2016-01-20 20:52:51 +01:00
|
|
|
#ifndef _INCLUDE__BASE__INTERNAL__LOCK_HELPER_H_
|
|
|
|
#define _INCLUDE__BASE__INTERNAL__LOCK_HELPER_H_
|
2012-02-29 15:23:06 +01:00
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
/* Genode includes */
|
|
|
|
#include <base/native_types.h>
|
|
|
|
#include <base/thread.h>
|
|
|
|
|
|
|
|
/* Fiasco.OC includes */
|
|
|
|
namespace Fiasco {
|
|
|
|
#include <l4/sys/kdebug.h>
|
|
|
|
#include <l4/sys/irq.h>
|
|
|
|
#include <l4/sys/thread.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Yield CPU time
|
|
|
|
*/
|
|
|
|
static inline void thread_yield() { Fiasco::l4_thread_yield(); }
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom ExchangeRegisters wrapper for waking up a thread
|
|
|
|
*
|
|
|
|
* When waking up an lock applicant, we need to make sure that the thread was
|
|
|
|
* stopped beforehand. Therefore, we evaluate the previous thread state as
|
|
|
|
* returned by the 'L4_ExchangeRegisters' call.
|
|
|
|
*
|
|
|
|
* \return true if the thread was in blocking state
|
|
|
|
*/
|
2013-02-25 21:18:26 +01:00
|
|
|
static inline bool thread_check_stopped_and_restart(Genode::Thread_base *thread_base)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2013-02-25 21:18:26 +01:00
|
|
|
Genode::Native_thread_id tid = thread_base ?
|
2016-01-23 14:42:55 +01:00
|
|
|
thread_base->tid().kcap :
|
2013-02-25 21:18:26 +01:00
|
|
|
Fiasco::MAIN_THREAD_CAP;
|
2012-03-08 12:45:18 +01:00
|
|
|
Genode::Native_thread_id irq = tid + Fiasco::THREAD_IRQ_CAP;
|
|
|
|
Fiasco::l4_irq_trigger(irq);
|
2011-12-22 16:19:25 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Yield CPU time to the specified thread
|
|
|
|
*/
|
2013-02-25 21:18:26 +01:00
|
|
|
static inline void thread_switch_to(Genode::Thread_base *thread_base)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2013-02-25 21:18:26 +01:00
|
|
|
Genode::Native_thread_id tid = thread_base ?
|
2016-01-23 14:42:55 +01:00
|
|
|
thread_base->tid().kcap :
|
2013-02-25 21:18:26 +01:00
|
|
|
Fiasco::MAIN_THREAD_CAP;
|
2011-12-22 16:19:25 +01:00
|
|
|
Fiasco::l4_thread_switch(tid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unconditionally block the calling thread
|
|
|
|
*/
|
2014-03-03 19:45:53 +01:00
|
|
|
|
|
|
|
/* Build with frame pointer to make GDB backtraces work. See issue #1061. */
|
|
|
|
__attribute__((optimize("-fno-omit-frame-pointer")))
|
|
|
|
__attribute__((noinline))
|
|
|
|
__attribute__((used))
|
|
|
|
static void thread_stop_myself()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
|
|
|
using namespace Fiasco;
|
|
|
|
|
2013-02-25 21:18:26 +01:00
|
|
|
Genode::Thread_base *myself = Genode::Thread_base::myself();
|
|
|
|
Genode::Native_thread_id tid = myself ?
|
2016-01-23 14:42:55 +01:00
|
|
|
myself->tid().kcap :
|
2013-02-25 21:18:26 +01:00
|
|
|
Fiasco::MAIN_THREAD_CAP;
|
|
|
|
Genode::Native_thread_id irq = tid + THREAD_IRQ_CAP;
|
2011-12-22 16:19:25 +01:00
|
|
|
l4_irq_receive(irq, L4_IPC_NEVER);
|
|
|
|
}
|
2012-02-29 15:23:06 +01:00
|
|
|
|
2016-01-20 20:52:51 +01:00
|
|
|
#endif /* _INCLUDE__BASE__INTERNAL__LOCK_HELPER_H_ */
|