source: libcfa/src/concurrency/thread.cfa @ de917da3

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since de917da3 was ff79d5e, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Fixed park unpark to support park as first step of main()
Fixes #170?

  • Property mode set to 100644
File size: 2.4 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        ticket = 1;
31        state = Start;
32        preempted = __NO_PREEMPTION;
33        curr_cor = &self_cor;
34        self_mon.owner = &this;
35        self_mon.recursion = 1;
36        self_mon_p = &self_mon;
37        curr_cluster = &cl;
38        link.next = 0p;
39        link.prev = 0p;
40
41        node.next = 0p;
42        node.prev = 0p;
43        doregister(curr_cluster, this);
44
45        monitors{ &self_mon_p, 1, (fptr_t)0 };
46}
47
48void ^?{}($thread& this) with( this ) {
49        unregister(curr_cluster, this);
50        ^self_cor{};
51}
52
53//-----------------------------------------------------------------------------
54// Starting and stopping threads
55forall( dtype T | is_thread(T) )
56void __thrd_start( T & this, void (*main_p)(T &) ) {
57        $thread * this_thrd = get_thread(this);
58
59        disable_interrupts();
60        __cfactx_start(main_p, get_coroutine(this), this, __cfactx_invoke_thread);
61
62        this_thrd->context.[SP, FP] = this_thrd->self_cor.context.[SP, FP];
63        verify( this_thrd->context.SP );
64
65        __schedule_thread( (__processor_id_t *)kernelTLS.this_processor, this_thrd);
66        enable_interrupts( __cfaabi_dbg_ctx );
67}
68
69//-----------------------------------------------------------------------------
70// Support for threads that don't ues the thread keyword
71forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
72void ?{}( scoped(T)& this ) with( this ) {
73        handle{};
74        __thrd_start(handle, main);
75}
76
77forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
78void ?{}( scoped(T)& this, P params ) with( this ) {
79        handle{ params };
80        __thrd_start(handle, main);
81}
82
83forall( dtype T | sized(T) | is_thread(T) )
84void ^?{}( scoped(T)& this ) with( this ) {
85        ^handle{};
86}
87
88// Local Variables: //
89// mode: c //
90// tab-width: 4 //
91// End: //
Note: See TracBrowser for help on using the repository browser.