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

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

Merge branch 'master' into relaxed_ready

  • Property mode set to 100644
File size: 2.7 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
25extern "C" {
26        #include <fenv.h>
27        #include <stddef.h>
28}
29
30//extern volatile thread_local processor * this_processor;
31
32//-----------------------------------------------------------------------------
33// Thread ctors and dtors
34void ?{}(thread_desc & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) {
35        context{ 0p, 0p };
36        self_cor{ name, storage, storageSize };
37        state = Start;
38        curr_cor = &self_cor;
39        self_mon.owner = &this;
40        self_mon.recursion = 1;
41        self_mon_p = &self_mon;
42        curr_cluster = &cl;
43        link.next = 0p;
44        link.prev = 0p;
45
46        node.next = 0p;
47        node.prev = 0p;
48        doregister(curr_cluster, this);
49
50        monitors{ &self_mon_p, 1, (fptr_t)0 };
51}
52
53void ^?{}(thread_desc& this) with( this ) {
54        unregister(curr_cluster, this);
55        ^self_cor{};
56}
57
58forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
59void ?{}( scoped(T)& this ) with( this ) {
60        handle{};
61        __thrd_start(handle, main);
62}
63
64forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
65void ?{}( scoped(T)& this, P params ) with( this ) {
66        handle{ params };
67        __thrd_start(handle, main);
68}
69
70forall( dtype T | sized(T) | is_thread(T) )
71void ^?{}( scoped(T)& this ) with( this ) {
72        ^handle{};
73}
74
75//-----------------------------------------------------------------------------
76// Starting and stopping threads
77forall( dtype T | is_thread(T) )
78void __thrd_start( T & this, void (*main_p)(T &) ) {
79        thread_desc * this_thrd = get_thread(this);
80
81        disable_interrupts();
82        CtxStart(main_p, get_coroutine(this), this, CtxInvokeThread);
83
84        this_thrd->context.[SP, FP] = this_thrd->self_cor.context.[SP, FP];
85        verify( this_thrd->context.SP );
86
87        ScheduleThread(this_thrd);
88        enable_interrupts( __cfaabi_dbg_ctx );
89}
90
91void yield( void ) {
92        // Safety note : This could cause some false positives due to preemption
93      verify( TL_GET( preemption_state.enabled ) );
94        BlockInternal( TL_GET( this_thread ) );
95        // Safety note : This could cause some false positives due to preemption
96      verify( TL_GET( preemption_state.enabled ) );
97}
98
99void yield( unsigned times ) {
100        for( unsigned i = 0; i < times; i++ ) {
101                yield();
102        }
103}
104
105// Local Variables: //
106// mode: c //
107// tab-width: 4 //
108// End: //
Note: See TracBrowser for help on using the repository browser.