source: libcfa/src/concurrency/thread.cfa @ 4e7c0fc0

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

Changed descriptors for concurrency to use $ prefix instead of trailing _desc

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