summary refs log tree commit diff stats
path: root/drnim/tests/tphi.nim
Commit message (Expand)AuthorAgeFilesLines
* drnim: phi nodes for 'if' statements (#13990)Andreas Rumpf2020-04-191-0/+23
'author Emery Hemingway <emery@vfemail.net> 2018-05-17 12:56:18 +0200 committer Emery Hemingway <emery@vfemail.net> 2018-06-07 07:21:20 +0200 Native access to Genode environment' href='/ahoang/Nim/commit/lib/genode_cpp/threads.h?h=devel&id=22f714585b943d0b2457c66a78917113072f4503'>22f714585 ^
7e351fc7f ^

















9258672ce ^





7e351fc7f ^






9258672ce ^

7e351fc7f ^























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73














                                                   
                     

















                                        





                                                                                                            






                                                

                                                                                                      























                                                                                    
/*
 *
 *           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