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

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

Optim : coroutine and thread creation no-longer uses polymorphic call, leading to significant speedup. Breaks Arm support

  • Property mode set to 100644
File size: 2.8 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 next = 0p;
44
45 node.next = 0p;
46 node.prev = 0p;
47 doregister(curr_cluster, this);
48
49 monitors{ &self_mon_p, 1, (fptr_t)0 };
50}
51
52void ^?{}(thread_desc& this) with( this ) {
53 unregister(curr_cluster, this);
54 ^self_cor{};
55}
56
57forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
58void ?{}( scoped(T)& this ) with( this ) {
59 handle{};
60 __thrd_start(handle, main);
61}
62
63forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
64void ?{}( scoped(T)& this, P params ) with( this ) {
65 handle{ params };
66 __thrd_start(handle, main);
67}
68
69forall( dtype T | sized(T) | is_thread(T) )
70void ^?{}( scoped(T)& this ) with( this ) {
71 ^handle{};
72}
73
74//-----------------------------------------------------------------------------
75// Starting and stopping threads
76forall( dtype T | is_thread(T) )
77void __thrd_start( T & this, void (*main_p)(T &) ) {
78 thread_desc * this_thrd = get_thread(this);
79 thread_desc * curr_thrd = TL_GET( this_thread );
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 // CtxSwitch( &curr_thrd->context, &this_thrd->context );
87
88 ScheduleThread(this_thrd);
89 enable_interrupts( __cfaabi_dbg_ctx );
90}
91
92void yield( void ) {
93 // Safety note : This could cause some false positives due to preemption
94 verify( TL_GET( preemption_state.enabled ) );
95 BlockInternal( TL_GET( this_thread ) );
96 // Safety note : This could cause some false positives due to preemption
97 verify( TL_GET( preemption_state.enabled ) );
98}
99
100void yield( unsigned times ) {
101 for( unsigned i = 0; i < times; i++ ) {
102 yield();
103 }
104}
105
106// Local Variables: //
107// mode: c //
108// tab-width: 4 //
109// End: //
Note: See TracBrowser for help on using the repository browser.