2011-12-22 16:19:25 +01:00
|
|
|
/*
|
2016-04-29 13:23:19 +02:00
|
|
|
* \brief Implementation of the Thread API
|
2011-12-22 16:19:25 +01:00
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2010-01-19
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2010-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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/thread.h>
|
2016-07-29 17:15:42 +02:00
|
|
|
#include <base/log.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <base/sleep.h>
|
|
|
|
#include <base/env.h>
|
2016-05-10 18:05:38 +02:00
|
|
|
#include <cpu_thread/client.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-01-23 14:42:55 +01:00
|
|
|
/* base-internal includes */
|
|
|
|
#include <base/internal/stack.h>
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Entry point entered by new threads
|
|
|
|
*/
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::_thread_start()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
Thread::myself()->_thread_bootstrap();
|
2016-07-29 17:15:42 +02:00
|
|
|
|
|
|
|
/* catch any exception at this point and try to print an error message */
|
|
|
|
try {
|
|
|
|
Thread::myself()->entry();
|
|
|
|
} catch (...) {
|
|
|
|
try {
|
|
|
|
raw("Thread '", Thread::myself()->name().string(),
|
|
|
|
"' died because of an uncaught exception");
|
|
|
|
} catch (...) {
|
|
|
|
/* die in a noisy way */
|
|
|
|
*(unsigned long *)0 = 0xdead;
|
|
|
|
}
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
Thread::myself()->_join_lock.unlock();
|
2016-07-29 17:15:42 +02:00
|
|
|
|
|
|
|
/* sleep silently */
|
2011-12-22 16:19:25 +01:00
|
|
|
Genode::sleep_forever();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
/************
|
|
|
|
** Thread **
|
|
|
|
************/
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::_deinit_platform_thread()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2014-04-29 09:45:47 +02:00
|
|
|
if (!_cpu_session)
|
2017-01-09 15:18:49 +01:00
|
|
|
_cpu_session = env_deprecated()->cpu_session();
|
2014-04-29 09:45:47 +02:00
|
|
|
|
2014-04-03 14:18:52 +02:00
|
|
|
_cpu_session->kill_thread(_thread_cap);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::start()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
/* if no CPU session is given, use it from the environment */
|
2014-04-03 14:18:52 +02:00
|
|
|
if (!_cpu_session)
|
2017-01-09 15:18:49 +01:00
|
|
|
_cpu_session = env_deprecated()->cpu_session();
|
2014-04-03 14:18:52 +02:00
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
/* create thread at core */
|
2016-01-23 14:42:55 +01:00
|
|
|
addr_t const utcb = (addr_t)&_stack->utcb();
|
2017-01-09 15:18:49 +01:00
|
|
|
_thread_cap = _cpu_session->create_thread(env_deprecated()->pd_session_cap(), name(),
|
2016-05-04 12:27:17 +02:00
|
|
|
_affinity, Weight(), utcb);
|
2015-03-13 11:20:44 +01:00
|
|
|
if (!_thread_cap.valid())
|
|
|
|
throw Cpu_session::Thread_creation_failed();
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-04-20 21:12:57 +02:00
|
|
|
/* start execution at initial instruction pointer and stack pointer */
|
2016-05-10 18:05:38 +02:00
|
|
|
Cpu_thread_client(_thread_cap).start((addr_t)_thread_start, _stack->top());
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::cancel_blocking()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2016-05-10 18:05:38 +02:00
|
|
|
Cpu_thread_client(_thread_cap).cancel_blocking();
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|