// // 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" //----------------------------------------------------------------------------- // Thread ctors and dtors void ?{}($thread & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) { context{ 0p, 0p }; self_cor{ name, storage, storageSize }; ticket = 1; state = Start; preempted = __NO_PREEMPTION; curr_cor = &self_cor; self_mon.owner = &this; self_mon.recursion = 1; self_mon_p = &self_mon; curr_cluster = &cl; link.next = 0p; link.prev = 0p; link.preferred = -1; node.next = 0p; node.prev = 0p; doregister(curr_cluster, this); monitors{ &self_mon_p, 1, (fptr_t)0 }; } void ^?{}($thread& this) with( this ) { unregister(curr_cluster, this); ^self_cor{}; } //----------------------------------------------------------------------------- // Starting and stopping threads forall( dtype T | is_thread(T) ) void __thrd_start( T & this, void (*main_p)(T &) ) { $thread * this_thrd = get_thread(this); disable_interrupts(); __cfactx_start(main_p, get_coroutine(this), this, __cfactx_invoke_thread); this_thrd->context.[SP, FP] = this_thrd->self_cor.context.[SP, FP]; verify( this_thrd->context.SP ); __schedule_thread( (__processor_id_t *)kernelTLS.this_processor, this_thrd); enable_interrupts( __cfaabi_dbg_ctx ); } //----------------------------------------------------------------------------- // Support for threads that don't ues the thread keyword 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{}; } // Local Variables: // // mode: c // // tab-width: 4 // // End: //