Ignore:
Timestamp:
May 24, 2019, 10:19:41 AM (6 years ago)
Author:
Thierry Delisle <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:
d908563
Parents:
6a9d4b4 (diff), 292642a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/coroutine.hfa

    r6a9d4b4 r933f32f  
    4646//-----------------------------------------------------------------------------
    4747// Public coroutine API
    48 static inline void suspend();
     48static inline void suspend(void);
    4949
    5050forall(dtype T | is_coroutine(T))
    51 static inline void resume(T & cor);
     51static inline T & resume(T & cor);
    5252
    5353forall(dtype T | is_coroutine(T))
     
    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");
    6670}
    6771
    6872// Private wrappers for context switch and stack creation
    69 extern void CoroutineCtxSwitch(coroutine_desc * src, coroutine_desc * dst);
    70 extern void create_stack( coStack_t * this, unsigned int storageSize );
     73// Wrapper for co
     74static inline void CoroutineCtxSwitch(coroutine_desc* src, coroutine_desc* dst) {
     75        // set state of current coroutine to inactive
     76        src->state = src->state == Halted ? Halted : Inactive;
     77
     78        // set new coroutine that task is executing
     79        TL_GET( this_thread )->curr_cor = dst;
     80
     81        // context switch to specified coroutine
     82        verify( dst->context.SP );
     83        CtxSwitch( &src->context, &dst->context );
     84        // when CtxSwitch returns we are back in the src coroutine
     85
     86        // set state of new coroutine to active
     87        src->state = Active;
     88
     89        if( unlikely(src->cancellation != NULL) ) {
     90                _CtxCoroutine_Unwind(src->cancellation, src);
     91        }
     92}
     93
     94extern void __stack_prepare   ( __stack_info_t * this, size_t size /* ignored if storage already allocated */);
    7195
    7296// Suspend implementation inlined for performance
    73 static inline void suspend() {
     97static inline void suspend(void) {
    7498        // optimization : read TLS once and reuse it
    7599        // Safety note: this is preemption safe since if
     
    77101        // will also migrate which means this value will
    78102        // stay in syn with the TLS
    79         coroutine_desc * src = TL_GET( this_coroutine );
     103        coroutine_desc * src = TL_GET( this_thread )->curr_cor;
    80104
    81105        assertf( src->last != 0,
     
    93117// Resume implementation inlined for performance
    94118forall(dtype T | is_coroutine(T))
    95 static inline void resume(T & cor) {
     119static inline T & resume(T & cor) {
    96120        // optimization : read TLS once and reuse it
    97121        // Safety note: this is preemption safe since if
     
    99123        // will also migrate which means this value will
    100124        // stay in syn with the TLS
    101         coroutine_desc * src = TL_GET( this_coroutine );
     125        coroutine_desc * src = TL_GET( this_thread )->curr_cor;
    102126        coroutine_desc * dst = get_coroutine(cor);
    103127
    104         if( unlikely(!dst->stack.base) ) {
    105                 create_stack(&dst->stack, dst->stack.size);
     128        if( unlikely(dst->context.SP == NULL) ) {
     129                __stack_prepare(&dst->stack, 65000);
    106130                CtxStart(&cor, CtxInvokeCoroutine);
    107131        }
     
    121145        // always done for performance testing
    122146        CoroutineCtxSwitch( src, dst );
     147
     148        return cor;
    123149}
    124150
     
    129155        // will also migrate which means this value will
    130156        // stay in syn with the TLS
    131         coroutine_desc * src = TL_GET( this_coroutine );
     157        coroutine_desc * src = TL_GET( this_thread )->curr_cor;
    132158
    133159        // not resuming self ?
Note: See TracChangeset for help on using the changeset viewer.