source: libcfa/src/concurrency/thread.cfa @ 27273f9

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

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

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[78b3f52]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//
[75a17f1]7// thread.c --
[78b3f52]8//
9// Author           : Thierry Delisle
[f07e037]10// Created On       : Tue Jan 17 12:27:26 2017
[6b0b624]11// Last Modified By : Peter A. Buhr
[121be3e]12// Last Modified On : Wed Dec  4 09:17:49 2019
13// Update Count     : 9
[78b3f52]14//
15
[2026bb6]16#define __cforall_thread__
17
[58b6d1b]18#include "thread.hfa"
[78b3f52]19
[73abe95]20#include "kernel_private.hfa"
[8118303]21
22#define __CFA_INVOKE_PRIVATE__
23#include "invoke.h"
24
25//-----------------------------------------------------------------------------
26// Thread ctors and dtors
[ac2b598]27void ?{}($thread & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) {
[121be3e]28        context{ 0p, 0p };
[de6319f]29        self_cor{ name, storage, storageSize };
[e8e457e]30        state = Start;
[3381ed7]31        preempted = __NO_PREEMPTION;
[82c948c]32        curr_cor = &self_cor;
[65deb18]33        self_mon.owner = &this;
34        self_mon.recursion = 1;
35        self_mon_p = &self_mon;
[de6319f]36        curr_cluster = &cl;
[121be3e]37        next = 0p;
[de94a60]38
[121be3e]39        node.next = 0p;
40        node.prev = 0p;
[a1a17a7]41        doregister(curr_cluster, this);
[5ea06d6]42
[65deb18]43        monitors{ &self_mon_p, 1, (fptr_t)0 };
[8118303]44}
45
[ac2b598]46void ^?{}($thread& this) with( this ) {
[a1a17a7]47        unregister(curr_cluster, this);
[65deb18]48        ^self_cor{};
[8118303]49}
50
[8c50aed]51//-----------------------------------------------------------------------------
52// Starting and stopping threads
53forall( dtype T | is_thread(T) )
54void __thrd_start( T & this, void (*main_p)(T &) ) {
[ac2b598]55        $thread * this_thrd = get_thread(this);
[8c50aed]56
57        disable_interrupts();
[c7a900a]58        __cfactx_start(main_p, get_coroutine(this), this, __cfactx_invoke_thread);
[8c50aed]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
[242a902]69forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
[65deb18]70void ?{}( scoped(T)& this ) with( this ) {
71        handle{};
[09f357ec]72        __thrd_start(handle, main);
[8118303]73}
74
[242a902]75forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
[65deb18]76void ?{}( scoped(T)& this, P params ) with( this ) {
77        handle{ params };
[09f357ec]78        __thrd_start(handle, main);
[8118303]79}
80
[9f1695b]81forall( dtype T | sized(T) | is_thread(T) )
[65deb18]82void ^?{}( scoped(T)& this ) with( this ) {
83        ^handle{};
[8118303]84}
85
[78b3f52]86// Local Variables: //
87// mode: c //
88// tab-width: 4 //
[6a3d2e7]89// End: //
Note: See TracBrowser for help on using the repository browser.