source: libcfa/src/concurrency/thread.cfa@ 33e62f1b

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 33e62f1b was 6a490b2, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Merge branch 'master' into relaxed_ready

  • Property mode set to 100644
File size: 2.3 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// thread.c --
8//
9// Author : Thierry Delisle
10// Created On : Tue Jan 17 12:27:26 2017
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Wed Dec 4 09:17:49 2019
13// Update Count : 9
14//
15
16#define __cforall_thread__
17
18#include "thread.hfa"
19
20#include "kernel_private.hfa"
21
22#define __CFA_INVOKE_PRIVATE__
23#include "invoke.h"
24
25//-----------------------------------------------------------------------------
26// Thread ctors and dtors
27void ?{}($thread & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) {
28 context{ 0p, 0p };
29 self_cor{ name, storage, storageSize };
30 state = Start;
31 preempted = __NO_PREEMPTION;
32 curr_cor = &self_cor;
33 self_mon.owner = &this;
34 self_mon.recursion = 1;
35 self_mon_p = &self_mon;
36 curr_cluster = &cl;
37 link.next = 0p;
38 link.prev = 0p;
39
40 node.next = 0p;
41 node.prev = 0p;
42 doregister(curr_cluster, this);
43
44 monitors{ &self_mon_p, 1, (fptr_t)0 };
45}
46
47void ^?{}($thread& this) with( this ) {
48 unregister(curr_cluster, this);
49 ^self_cor{};
50}
51
52//-----------------------------------------------------------------------------
53// Starting and stopping threads
54forall( dtype T | is_thread(T) )
55void __thrd_start( T & this, void (*main_p)(T &) ) {
56 $thread * this_thrd = get_thread(this);
57
58 disable_interrupts();
59 __cfactx_start(main_p, get_coroutine(this), this, __cfactx_invoke_thread);
60
61 this_thrd->context.[SP, FP] = this_thrd->self_cor.context.[SP, FP];
62 verify( this_thrd->context.SP );
63
64 __schedule_thread(this_thrd);
65 enable_interrupts( __cfaabi_dbg_ctx );
66}
67
68//-----------------------------------------------------------------------------
69// Support for threads that don't ues the thread keyword
70forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
71void ?{}( scoped(T)& this ) with( this ) {
72 handle{};
73 __thrd_start(handle, main);
74}
75
76forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
77void ?{}( scoped(T)& this, P params ) with( this ) {
78 handle{ params };
79 __thrd_start(handle, main);
80}
81
82forall( dtype T | sized(T) | is_thread(T) )
83void ^?{}( scoped(T)& this ) with( this ) {
84 ^handle{};
85}
86
87// Local Variables: //
88// mode: c //
89// tab-width: 4 //
90// End: //
Note: See TracBrowser for help on using the repository browser.