Ignore:
Timestamp:
May 6, 2019, 10:09:02 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:
63364d8
Parents:
b9696a8
Message:

Some more work on suspend_then

Location:
libcfa/src/concurrency
Files:
3 edited

Legend:

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

    rb9696a8 rf019069  
    100100        movq %rbp,FP_OFFSET(%rdi)
    101101
     102        mfence
     103
    102104        // Don't load a new context, directly jump to the desired function
    103 
    104         jmp *%rsi
     105#if defined(PIC)
     106        call __suspend_callback@plt
     107#else
     108        call __suspend_callback
     109#endif
    105110        .size  CtxStore, .-CtxStore
    106111
  • libcfa/src/concurrency/coroutine.cfa

    rb9696a8 rf019069  
    4040                abort();
    4141        }
     42
     43        extern void CtxRet( struct __stack_context_t * to ) asm ("CtxRet") __attribute__ ((__noreturn__));
    4244}
    4345
     
    203205                CoroutineCtxSwitch( src, starter );
    204206        }
     207
     208        __attribute__((noreturn)) void __suspend_callback( struct __stack_context_t *, fptr_t call ) {
     209                call();
     210
     211                coroutine_desc * src = TL_GET( this_thread )->curr_cor;
     212                // set state of current coroutine to inactive
     213                src->state = src->state == Halted ? Halted : Inactive;
     214
     215                TL_GET( this_thread )->curr_cor = src->last;
     216
     217                // context switch to specified coroutine
     218                assert( src->last->context.SP );
     219                CtxRet( &src->last->context );
     220
     221                abort();
     222        }
    205223}
    206224
  • libcfa/src/concurrency/coroutine.hfa

    rb9696a8 rf019069  
    6868
    6969        extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch");
    70         extern void CtxStore ( struct __stack_context_t * from, __attribute__((noreturn)) void (*__callback)(void) ) asm ("CtxStore");
    71         extern void CtxRet   ( struct __stack_context_t * to ) asm ("CtxRet") __attribute__ ((__noreturn__));
     70        extern void CtxStore ( struct __stack_context_t * from, fptr_t callback ) asm ("CtxStore");
    7271}
    7372
     
    172171}
    173172
     173__attribute__((noreturn)) void __suspend_callback(void *, fptr_t call);
     174
    174175static inline void suspend_then(fptr_t call) {
    175176        // optimization : read TLS once and reuse it
     
    194195      assert( src->context.SP );
    195196
    196         __attribute__((noreturn)) void __suspend_callback(void) {
    197                 call();
    198 
    199                 // set state of current coroutine to inactive
    200                 src->state = src->state == Halted ? Halted : Inactive;
    201 
    202                 TL_GET( this_thread )->curr_cor = src->last;
    203 
    204                 // context switch to specified coroutine
    205                 assert( src->last->context.SP );
    206                 CtxRet( &src->last->context );
    207 
    208                 abort();
    209         }
    210       CtxStore( &src->context, __suspend_callback );
     197      CtxStore( &src->context, call );
    211198        // when CtxStore returns we are back in the src coroutine
    212199
     
    220207        return;
    221208}
    222 
    223 // static inline void suspend_return(void) {
    224 //      // optimization : read TLS once and reuse it
    225 //      // Safety note: this is preemption safe since if
    226 //      // preemption occurs after this line, the pointer
    227 //      // will also migrate which means this value will
    228 //      // stay in syn with the TLS
    229 //      coroutine_desc * src = TL_GET( this_thread )->curr_cor;
    230 
    231 //      assertf( src->last != 0,
    232 //              "Attempt to suspend coroutine \"%.256s\" (%p) that has never been resumed.\n"
    233 //              "Possible cause is a suspend executed in a member called by a coroutine user rather than by the coroutine main.",
    234 //              src->name, src );
    235 //      assertf( src->last->state != Halted,
    236 //              "Attempt by coroutine \"%.256s\" (%p) to suspend back to terminated coroutine \"%.256s\" (%p).\n"
    237 //              "Possible cause is terminated coroutine's main routine has already returned.",
    238 //              src->name, src, src->last->name, src->last );
    239 
    240 //      // Safety note : Preemption must be disabled here since kernelTLS.this_coroutine must always be up to date
    241 //       verify( TL_GET( preemption_state.enabled ) || TL_GET( this_processor )->do_terminate );
    242 //       disable_interrupts();
    243 
    244 //       // set state of current coroutine to inactive
    245 //       src->state = src->state == Halted ? Halted : Inactive;
    246 
    247 //       // set new coroutine that task is executing
    248 //       kernelTLS.this_coroutine = dst;
    249 
    250 //       // context switch to specified coroutine
    251 //       assert( src->stack.context );
    252 //      CtxRet( src->stack.context );
    253 
    254 //      abort();
    255 // }
    256209
    257210// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.