From de0a771faeae80451c5f112b87c55be1b47343d2 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Wed, 30 Apr 2014 16:30:40 +0200 Subject: [PATCH] Generic sleep_forever() based on lock The old implementation of sleep_forever() used a local Ipc_server object, which is not announced (i.e., known) outside of the blocking process/thread, to infinitely wait for incoming messages. In past and present, this leads to problems (e.g., issues #538 and #1032). Fixes #1135. Fixes #538. Fixes #1032. --- base-fiasco/include/base/cancelable_lock.h | 3 +- base-fiasco/include/base/sleep.h | 31 ++++++++++++++++++++ base-foc/src/base/thread/thread_bootstrap.cc | 4 +-- base/include/base/sleep.h | 10 +++---- os/include/platform/pbxa9/pl011_defs.h | 1 + os/include/platform/vpb926/pl011_defs.h | 2 ++ 6 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 base-fiasco/include/base/sleep.h diff --git a/base-fiasco/include/base/cancelable_lock.h b/base-fiasco/include/base/cancelable_lock.h index d2bfcf74f..c684501da 100644 --- a/base-fiasco/include/base/cancelable_lock.h +++ b/base-fiasco/include/base/cancelable_lock.h @@ -15,7 +15,6 @@ #define _INCLUDE__BASE__CANCELABLE_LOCK_H_ #include -#include #include namespace Genode { @@ -33,7 +32,7 @@ namespace Genode { /** * Constructor */ - Cancelable_lock(State initial = UNLOCKED); + explicit Cancelable_lock(State initial = UNLOCKED); /** * Try to aquire lock an block while lock is not free diff --git a/base-fiasco/include/base/sleep.h b/base-fiasco/include/base/sleep.h new file mode 100644 index 000000000..9a05e8e51 --- /dev/null +++ b/base-fiasco/include/base/sleep.h @@ -0,0 +1,31 @@ +/* + * \brief Lay back and relax + * \author Norman Feske + * \author Christian Helmuth + * \date 2006-07-19 + */ + +/* + * Copyright (C) 2006-2014 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__SLEEP_H_ +#define _INCLUDE__BASE__SLEEP_H_ + +/* L4/Fiasco includes */ +namespace Fiasco { +#include +} + +namespace Genode { + + __attribute__((noreturn)) inline void sleep_forever() + { + while (true) Fiasco::l4_ipc_sleep((Fiasco::l4_timeout_t){0}); + } +} + +#endif /* _INCLUDE__BASE__SLEEP_H_ */ diff --git a/base-foc/src/base/thread/thread_bootstrap.cc b/base-foc/src/base/thread/thread_bootstrap.cc index 25a521e0e..b556f1c52 100644 --- a/base-foc/src/base/thread/thread_bootstrap.cc +++ b/base-foc/src/base/thread/thread_bootstrap.cc @@ -15,6 +15,7 @@ /* Genode includes */ #include #include +#include /***************************** @@ -54,6 +55,5 @@ void Genode::Thread_base::_thread_start() Thread_base::myself()->_thread_bootstrap(); Thread_base::myself()->entry(); Thread_base::myself()->_join_lock.unlock(); - Lock sleep_forever_lock(Lock::LOCKED); - sleep_forever_lock.lock(); + sleep_forever(); } diff --git a/base/include/base/sleep.h b/base/include/base/sleep.h index bd158a682..98f7403dc 100644 --- a/base/include/base/sleep.h +++ b/base/include/base/sleep.h @@ -1,11 +1,12 @@ /* * \brief Lay back and relax * \author Norman Feske + * \author Christian Helmuth * \date 2006-07-19 */ /* - * Copyright (C) 2006-2013 Genode Labs GmbH + * Copyright (C) 2006-2014 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. @@ -14,15 +15,14 @@ #ifndef _INCLUDE__BASE__SLEEP_H_ #define _INCLUDE__BASE__SLEEP_H_ -#include +#include namespace Genode { __attribute__((noreturn)) inline void sleep_forever() { - Msgbuf<16> buf; - Ipc_server s(&buf, &buf); - while (1) s >> IPC_WAIT; + Lock sleep; + while (true) sleep.lock(); } } diff --git a/os/include/platform/pbxa9/pl011_defs.h b/os/include/platform/pbxa9/pl011_defs.h index 226839808..c6cd3f637 100644 --- a/os/include/platform/pbxa9/pl011_defs.h +++ b/os/include/platform/pbxa9/pl011_defs.h @@ -14,6 +14,7 @@ #ifndef _INCLUDE__PLATFORM__PBXA9__PL011_DEFS_H_ #define _INCLUDE__PLATFORM__PBXA9__PL011_DEFS_H_ +#include #include enum { diff --git a/os/include/platform/vpb926/pl011_defs.h b/os/include/platform/vpb926/pl011_defs.h index d43535ddd..ed702a240 100644 --- a/os/include/platform/vpb926/pl011_defs.h +++ b/os/include/platform/vpb926/pl011_defs.h @@ -14,6 +14,8 @@ #ifndef _INCLUDE__PLATFORM__VPB926__PL011_DEFS_H_ #define _INCLUDE__PLATFORM__VPB926__PL011_DEFS_H_ +#include + #warning pl011 untested on vpb926 enum {