Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/thread.cfa

    rac2b598 r5b2b42e  
    2323#include "invoke.h"
    2424
     25extern "C" {
     26        #include <fenv.h>
     27        #include <stddef.h>
     28}
     29
     30//extern volatile thread_local processor * this_processor;
     31
    2532//-----------------------------------------------------------------------------
    2633// Thread ctors and dtors
    27 void ?{}($thread & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) {
     34void ?{}(thread_desc & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) {
    2835        context{ 0p, 0p };
    2936        self_cor{ name, storage, storageSize };
    3037        state = Start;
    31         preempted = __NO_PREEMPTION;
    3238        curr_cor = &self_cor;
    3339        self_mon.owner = &this;
     
    4450}
    4551
    46 void ^?{}($thread& this) with( this ) {
     52void ^?{}(thread_desc& this) with( this ) {
    4753        unregister(curr_cluster, this);
    4854        ^self_cor{};
    4955}
    5056
    51 //-----------------------------------------------------------------------------
    52 // Starting and stopping threads
    53 forall( dtype T | is_thread(T) )
    54 void __thrd_start( T & this, void (*main_p)(T &) ) {
    55         $thread * this_thrd = get_thread(this);
    56 
    57         disable_interrupts();
    58         __cfactx_start(main_p, get_coroutine(this), this, __cfactx_invoke_thread);
    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
    6957forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
    7058void ?{}( scoped(T)& this ) with( this ) {
     
    8472}
    8573
     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
     80        disable_interrupts();
     81        CtxStart(main_p, get_coroutine(this), this, CtxInvokeThread);
     82
     83        this_thrd->context.[SP, FP] = this_thrd->self_cor.context.[SP, FP];
     84        verify( this_thrd->context.SP );
     85
     86        ScheduleThread(this_thrd);
     87        enable_interrupts( __cfaabi_dbg_ctx );
     88}
     89
     90void yield( void ) {
     91        // Safety note : This could cause some false positives due to preemption
     92      verify( TL_GET( preemption_state.enabled ) );
     93        BlockInternal( TL_GET( this_thread ) );
     94        // Safety note : This could cause some false positives due to preemption
     95      verify( TL_GET( preemption_state.enabled ) );
     96}
     97
     98void yield( unsigned times ) {
     99        for( unsigned i = 0; i < times; i++ ) {
     100                yield();
     101        }
     102}
     103
    86104// Local Variables: //
    87105// mode: c //
Note: See TracChangeset for help on using the changeset viewer.