From 5e940da0408efb578fe5baebadcc7e2eb97eaa59 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Sun, 16 Mar 2014 15:33:45 +0100 Subject: [PATCH] hw: don't use assert in Kernel::pause_thread ref #1101 --- base-hw/src/core/kernel/thread.cc | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/base-hw/src/core/kernel/thread.cc b/base-hw/src/core/kernel/thread.cc index 2249386ba..dae8a7ad7 100644 --- a/base-hw/src/core/kernel/thread.cc +++ b/base-hw/src/core/kernel/thread.cc @@ -382,21 +382,28 @@ void Thread::_call_start_thread() void Thread::_call_pause_thread() { - unsigned const tid = user_arg_1(); - - /* shortcut for a thread to pause itself */ - if (!tid) { + /* take a shortcut if a thread wants to pause itself */ + unsigned const thread_id = user_arg_1(); + if (!thread_id || thread_id == id()) { _pause(); user_arg_0(0); return; } - - /* get targeted thread and check permissions */ - Thread * const t = Thread::pool()->object(tid); - assert(t && (_core() || this == t)); - - /* pause targeted thread */ - t->_pause(); + /* check permissions */ + if (!_core()) { + PWRN("not entitled to pause thread"); + _stop(); + return; + } + /* lookup thread */ + Thread * const thread = Thread::pool()->object(thread_id); + if (!thread) { + PWRN("failed to lookup thread"); + user_arg_0(-1); + return; + } + /* pause thread */ + thread->_pause(); user_arg_0(0); }