Files
Nim/lib/genode_cpp/threads.h
Emery Hemingway 22f714585b Native access to Genode environment
Add a 'GenodeEnv' type and a 'componentConstructHook' to the system
module. The 'componentConstructHook' allows for detection of POSIX style
programs that exit implicitly or native Genode components that
initialize to serve RPC requests and OS signals.

This hook takes a 'GenodeEnv' argument so that the environment interface
is passed cleanly to application code after globals are initialized.
This is an typed pointer to a C++ object, procedures for accessing the
environment will be available from a Nimble library and not included in
the standard library.

The standard library has an internal pointer to the environment object
but this is not for external use, the undocumented global environment
pointer has been removed.
2018-06-07 07:21:20 +02:00

74 lines
1.6 KiB
C++

/*
*
* Nim's Runtime Library
* (c) Copyright 2017 Emery Hemingway
*
* See the file "copying.txt", included in this
* distribution, for details about the copyright.
*
*/
#ifndef _GENODE_CPP__THREAD_H_
#define _GENODE_CPP__THREAD_H_
#include <base/thread.h>
#include <base/env.h>
#include <util/reconstructible.h>
namespace Nim { struct SysThread; }
struct Nim::SysThread
{
typedef void (Entry)(void*);
struct Thread : Genode::Thread
{
void *_tls;
Entry *_func;
void *_arg;
void entry() override {
(_func)(_arg); }
Thread(Genode::Env &env, Genode::size_t stack_size, Entry func, void *arg, int affinity)
: Genode::Thread(env, "nim-thread", stack_size,
env.cpu().affinity_space().location_of_index(affinity),
Genode::Cpu_session::Weight(Genode::Cpu_session::Weight::DEFAULT_WEIGHT-1),
env.cpu()),
_func(func), _arg(arg)
{
Genode::Thread::start();
}
};
Genode::Constructible<Thread> _thread;
void initThread(Genode::Env *env, Genode::size_t stack_size, Entry func, void *arg, int aff) {
_thread.construct(*env, stack_size, func, arg, aff); }
void joinThread() {
_thread->join(); }
static bool offMainThread() {
return dynamic_cast<SysThread::Thread*>(Genode::Thread::myself()); }
static void *threadVarGetValue()
{
SysThread::Thread *thr =
static_cast<SysThread::Thread*>(Genode::Thread::myself());
return thr->_tls;
}
static void threadVarSetValue(void *value)
{
SysThread::Thread *thr =
static_cast<SysThread::Thread*>(Genode::Thread::myself());
thr->_tls = value;
}
};
#endif