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.
|
|
|
|
*/
|
|
|
|
|
2013-11-19 15:13:24 +01:00
|
|
|
#ifndef _LOCK_HELPER_H_
|
|
|
|
#define _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>
|
|
|
|
|
2013-11-19 15:13:24 +01:00
|
|
|
extern Genode::Native_thread_id _main_thread_id;
|
2013-02-25 21:18:26 +01:00
|
|
|
|
2013-11-19 15:13:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Yield execution time-slice of current thread
|
|
|
|
*/
|
2013-11-25 10:57:07 +01:00
|
|
|
static inline void thread_yield() { Kernel::yield_thread(0); }
|
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
|
|
|
*/
|
2013-11-19 15:13:24 +01:00
|
|
|
static inline Genode::Native_thread_id
|
|
|
|
native_thread_id(Genode::Thread_base * const t)
|
|
|
|
{
|
|
|
|
return t ? t->tid().thread_id : _main_thread_id;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
2013-11-19 15:13:24 +01:00
|
|
|
#endif /* _LOCK_HELPER_H_ */
|
2012-05-30 20:13:09 +02:00
|
|
|
|