// // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // thread.c -- // // Author : Thierry Delisle // Created On : Tue Jan 17 12:27:26 2017 // Last Modified By : Peter A. Buhr // Last Modified On : Wed Dec 4 09:17:49 2019 // Update Count : 9 // #define __cforall_thread__ #include "thread.hfa" #include "kernel_private.hfa" #define __CFA_INVOKE_PRIVATE__ #include "invoke.h" extern "C" { #include #include } //extern volatile thread_local processor * this_processor; //----------------------------------------------------------------------------- // Thread ctors and dtors void ?{}(thread_desc & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) { context{ 0p, 0p }; self_cor{ name, storage, storageSize }; state = Start; curr_cor = &self_cor; self_mon.owner = &this; self_mon.recursion = 1; self_mon_p = &self_mon; curr_cluster = &cl; next = 0p; node.next = 0p; node.prev = 0p; doregister(curr_cluster, this); monitors{ &self_mon_p, 1, (fptr_t)0 }; } void ^?{}(thread_desc& this) with( this ) { unregister(curr_cluster, this); ^self_cor{}; } forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } ) void ?{}( scoped(T)& this ) with( this ) { handle{}; __thrd_start(handle, main); } forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } ) void ?{}( scoped(T)& this, P params ) with( this ) { handle{ params }; __thrd_start(handle, main); } forall( dtype T | sized(T) | is_thread(T) ) void ^?{}( scoped(T)& this ) with( this ) { ^handle{}; } //----------------------------------------------------------------------------- // Starting and stopping threads forall( dtype T | is_thread(T) ) void __thrd_start( T & this, void (*main_p)(T &) ) { thread_desc * this_thrd = get_thread(this); disable_interrupts(); CtxStart(main_p, get_coroutine(this), this, CtxInvokeThread); this_thrd->context.[SP, FP] = this_thrd->self_cor.context.[SP, FP]; verify( this_thrd->context.SP ); ScheduleThread(this_thrd); enable_interrupts( __cfaabi_dbg_ctx ); } void yield( void ) { // Safety note : This could cause some false positives due to preemption verify( TL_GET( preemption_state.enabled ) ); BlockInternal( TL_GET( this_thread ) ); // Safety note : This could cause some false positives due to preemption verify( TL_GET( preemption_state.enabled ) ); } void yield( unsigned times ) { for( unsigned i = 0; i < times; i++ ) { yield(); } } // Local Variables: // // mode: c // // tab-width: 4 // // End: //