diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-04-02 23:44:50 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-04-02 23:44:50 +0200 |
commit | 57b7c45128bc4257157ce905537db2f3fb970b7b (patch) | |
tree | 98db34a7b987dd7135792615a58e75ba58e15e38 /lib/genode_cpp/threads.h | |
parent | c785066ee343268c5ef9c19c4d334a0f1e8e8c48 (diff) | |
parent | cab2ce7e8770f35561f002bab601358a09535ef2 (diff) | |
download | Nim-57b7c45128bc4257157ce905537db2f3fb970b7b.tar.gz |
Merge branch 'devel' into araq
Diffstat (limited to 'lib/genode_cpp/threads.h')
-rw-r--r-- | lib/genode_cpp/threads.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/genode_cpp/threads.h b/lib/genode_cpp/threads.h new file mode 100644 index 000000000..a1cd61cd2 --- /dev/null +++ b/lib/genode_cpp/threads.h @@ -0,0 +1,69 @@ +/* + * + * 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 <util/avl_tree.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) + : Genode::Thread(env, "nim-thread", stack_size), _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) { + _thread.construct(*env, stack_size, func, arg); } + + 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 |