2012-05-30 20:13:09 +02:00
|
|
|
/*
|
2013-11-19 15:13:24 +01:00
|
|
|
* \brief Helper functions for the lock implementation
|
2012-05-30 20:13:09 +02:00
|
|
|
* \author Martin Stein
|
|
|
|
* \date 2011-01-02
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2011-2013 Genode Labs GmbH
|
2012-05-30 20:13:09 +02: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-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/native_types.h>
|
2013-02-25 21:18:26 +01:00
|
|
|
#include <base/thread.h>
|
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
namespace Hw {
|
|
|
|
extern Genode::Untyped_capability _main_thread_cap;
|
|
|
|
}
|
2013-11-19 15:13:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Yield execution time-slice of current thread
|
|
|
|
*/
|
2015-05-19 14:18:40 +02:00
|
|
|
static inline void thread_yield() {
|
|
|
|
Kernel::yield_thread(Kernel::cap_id_invalid()); }
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-11-19 15:13:24 +01:00
|
|
|
* Return kernel name of thread t
|
2012-05-30 20:13:09 +02:00
|
|
|
*/
|
2016-03-08 17:44:54 +01:00
|
|
|
static inline Kernel::capid_t
|
2013-11-19 15:13:24 +01:00
|
|
|
native_thread_id(Genode::Thread_base * const t)
|
|
|
|
{
|
2015-05-19 14:18:40 +02:00
|
|
|
return t ? t->tid().cap.dst() : Hw::_main_thread_cap.dst();
|
2013-11-19 15:13:24 +01:00
|
|
|
}
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-11-19 15:13:24 +01:00
|
|
|
* Yield execution time-slice of current thread to thread t
|
2012-05-30 20:13:09 +02:00
|
|
|
*/
|
2013-11-19 15:13:24 +01:00
|
|
|
static inline void thread_switch_to(Genode::Thread_base * const t)
|
2013-02-25 21:18:26 +01:00
|
|
|
{
|
2013-11-19 15:13:24 +01:00
|
|
|
Kernel::yield_thread(native_thread_id(t));
|
2013-02-25 21:18:26 +01:00
|
|
|
}
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-11-19 15:13:24 +01:00
|
|
|
* Resume thread t and return wether t was paused or not
|
2012-05-30 20:13:09 +02:00
|
|
|
*/
|
|
|
|
static inline bool
|
2013-11-19 15:13:24 +01:00
|
|
|
thread_check_stopped_and_restart(Genode::Thread_base * const t)
|
2013-02-25 21:18:26 +01:00
|
|
|
{
|
2014-03-25 16:34:20 +01:00
|
|
|
return Kernel::resume_local_thread(native_thread_id(t));
|
2013-02-25 21:18:26 +01:00
|
|
|
}
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-11-19 15:13:24 +01:00
|
|
|
* Pause execution of current thread
|
2012-05-30 20:13:09 +02:00
|
|
|
*/
|
2014-03-16 16:00:55 +01:00
|
|
|
static inline void thread_stop_myself() { Kernel::pause_current_thread(); }
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
|
2016-01-20 20:52:51 +01:00
|
|
|
#endif /* _INCLUDE__BASE__INTERNAL__LOCK_HELPER_H_ */
|