Changeset 3c06bba


Ignore:
Timestamp:
Apr 15, 2019, 4:06:40 PM (5 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
deca0f5
Parents:
5c1a531
Message:

Inlined coroutine context switch routine

Location:
libcfa/src/concurrency
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/CtxSwitch-i386.S

    r5c1a531 r3c06bba  
    4141#define PC_OFFSET       ( 2 * PTR_BYTE )
    4242
    43 .text
     43        .text
    4444        .align 2
    45 .globl  CtxSwitch
     45        .globl CtxSwitch
     46        .type  CtxSwitch, @function
    4647CtxSwitch:
    4748
     
    9495
    9596        ret
     97        .size  CtxSwitch, .-CtxSwitch
    9698
    9799// Local Variables: //
  • libcfa/src/concurrency/CtxSwitch-x86_64.S

    r5c1a531 r3c06bba  
    4040#define FP_OFFSET       ( 1 * PTR_BYTE )
    4141
    42 .text
     42        .text
    4343        .align 2
    44 .globl  CtxSwitch
     44        .globl CtxSwitch
     45        .type  CtxSwitch, @function
    4546CtxSwitch:
    4647
     
    8687
    8788        ret
     89        .size  CtxSwitch, .-CtxSwitch
     90
    8891
    8992//.text
  • libcfa/src/concurrency/coroutine.cfa

    r5c1a531 r3c06bba  
    124124}
    125125
    126 // Wrapper for co
    127 void CoroutineCtxSwitch(coroutine_desc* src, coroutine_desc* dst) {
    128         // set state of current coroutine to inactive
    129         src->state = src->state == Halted ? Halted : Inactive;
    130 
    131         // set new coroutine that task is executing
    132         TL_GET( this_thread )->curr_cor = dst;
    133 
    134         // context switch to specified coroutine
    135         verify( dst->context.SP );
    136         CtxSwitch( &src->context, &dst->context );
    137         // when CtxSwitch returns we are back in the src coroutine
    138 
    139         // set state of new coroutine to active
    140         src->state = Active;
    141 
    142         if( unlikely(src->cancellation != NULL) ) {
    143                 _CtxCoroutine_Unwind(src->cancellation, src);
    144         }
    145 }
    146 
    147126[void *, size_t] __stack_alloc( size_t storageSize ) {
    148127        static const size_t stack_data_size = libCeiling( sizeof(__stack_t), 16 ); // minimum alignment
  • libcfa/src/concurrency/coroutine.hfa

    r5c1a531 r3c06bba  
    6464      forall(dtype T | is_coroutine(T))
    6565      void CtxStart(T * this, void ( *invoke)(T *));
     66
     67        extern void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc *) __attribute__ ((__noreturn__));
     68
     69        extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch");
     70        // void CtxStore ( void * this ) asm ("CtxStore");
     71        // void CtxRet   ( void * dst  ) asm ("CtxRet");
    6672}
    6773
    6874// Private wrappers for context switch and stack creation
    69 extern void CoroutineCtxSwitch(coroutine_desc * src, coroutine_desc * dst);
     75// Wrapper for co
     76static inline void CoroutineCtxSwitch(coroutine_desc* src, coroutine_desc* dst) {
     77        // set state of current coroutine to inactive
     78        src->state = src->state == Halted ? Halted : Inactive;
     79
     80        // set new coroutine that task is executing
     81        TL_GET( this_thread )->curr_cor = dst;
     82
     83        // context switch to specified coroutine
     84        verify( dst->context.SP );
     85        CtxSwitch( &src->context, &dst->context );
     86        // when CtxSwitch returns we are back in the src coroutine
     87
     88        // set state of new coroutine to active
     89        src->state = Active;
     90
     91        if( unlikely(src->cancellation != NULL) ) {
     92                _CtxCoroutine_Unwind(src->cancellation, src);
     93        }
     94}
     95
    7096extern void __stack_prepare   ( __stack_info_t * this, size_t size /* ignored if storage already allocated */);
    7197
  • libcfa/src/concurrency/invoke.h

    r5c1a531 r3c06bba  
    260260        // assembler routines that performs the context switch
    261261        extern void CtxInvokeStub( void );
    262         void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch");
     262        extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch");
    263263        // void CtxStore ( void * this ) asm ("CtxStore");
    264264        // void CtxRet   ( void * dst  ) asm ("CtxRet");
Note: See TracChangeset for help on using the changeset viewer.