Changeset 63364d8


Ignore:
Timestamp:
May 9, 2019, 4:47:28 PM (5 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:
b038fe4
Parents:
f019069
Message:

Removed suspend_then since I believe it cannot be made correct

Files:
2 deleted
4 edited

Legend:

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

    rf019069 r63364d8  
    8080
    8181//-----------------------------------------------------------------------------
    82 // Part of a 2 part context switch routine, use with CtxRet, stores the current context and then makes a function call
    83         .text
    84         .align 2
    85         .globl CtxStore
    86         .type  CtxStore, @function
    87 CtxStore:
    88 
    89         // Save volatile registers on the stack.
    90 
    91         pushq %r15
    92         pushq %r14
    93         pushq %r13
    94         pushq %r12
    95         pushq %rbx
    96 
    97         // Save old context in the "from" area.
    98 
    99         movq %rsp,SP_OFFSET(%rdi)
    100         movq %rbp,FP_OFFSET(%rdi)
    101 
    102         mfence
    103 
    104         // Don't load a new context, directly jump to the desired function
    105 #if defined(PIC)
    106         call __suspend_callback@plt
    107 #else
    108         call __suspend_callback
    109 #endif
    110         .size  CtxStore, .-CtxStore
    111 
    112 //-----------------------------------------------------------------------------
    113 // Part of a 2 part context switch routine, use with CtxStore, context switches to the desired target without saving the current context
    114         .text
    115         .align 2
    116         .globl CtxRet
    117         .type  CtxRet, @function
    118 CtxRet:
    119         // Load new context from the "to" area.
    120 
    121         movq SP_OFFSET(%rdi),%rsp
    122         movq FP_OFFSET(%rdi),%rbp
    123 
    124         // Load volatile registers from the stack.
    125 
    126         popq %rbx
    127         popq %r12
    128         popq %r13
    129         popq %r14
    130         popq %r15
    131 
    132         // Return to thread.
    133 
    134         ret
    135         .size  CtxRet, .-CtxRet
    136 
    137 
    138 //-----------------------------------------------------------------------------
    13982// Stub used to create new stacks which are ready to be context switched to
    14083        .text
  • libcfa/src/concurrency/coroutine.cfa

    rf019069 r63364d8  
    205205                CoroutineCtxSwitch( src, starter );
    206206        }
    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         }
    223207}
    224208
  • libcfa/src/concurrency/coroutine.hfa

    rf019069 r63364d8  
    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, fptr_t callback ) asm ("CtxStore");
    7170}
    7271
     
    171170}
    172171
    173 __attribute__((noreturn)) void __suspend_callback(void *, fptr_t call);
    174 
    175 static inline void suspend_then(fptr_t call) {
    176         // optimization : read TLS once and reuse it
    177         // Safety note: this is preemption safe since if
    178         // preemption occurs after this line, the pointer
    179         // will also migrate which means this value will
    180         // stay in syn with the TLS
    181         coroutine_desc * src = TL_GET( this_thread )->curr_cor;
    182 
    183         assertf( src->last != 0,
    184                 "Attempt to suspend coroutine \"%.256s\" (%p) that has never been resumed.\n"
    185                 "Possible cause is a suspend executed in a member called by a coroutine user rather than by the coroutine main.",
    186                 src->name, src );
    187         assertf( src->last->state != Halted,
    188                 "Attempt by coroutine \"%.256s\" (%p) to suspend back to terminated coroutine \"%.256s\" (%p).\n"
    189                 "Possible cause is terminated coroutine's main routine has already returned.",
    190                 src->name, src, src->last->name, src->last );
    191 
    192         src->state = PreInactive;
    193 
    194       // context switch to specified coroutine
    195       assert( src->context.SP );
    196 
    197       CtxStore( &src->context, call );
    198         // when CtxStore returns we are back in the src coroutine
    199 
    200         // set state of new coroutine to active
    201         src->state = Active;
    202 
    203         if( unlikely(src->cancellation != NULL) ) {
    204                 _CtxCoroutine_Unwind(src->cancellation, src);
    205         }
    206 
    207         return;
    208 }
    209 
    210172// Local Variables: //
    211173// mode: c //
  • libcfa/src/concurrency/invoke.h

    rf019069 r63364d8  
    9393        };
    9494
    95         enum coroutine_state { Halted, Start, Inactive, Active, Primed, PreInactive };
     95        enum coroutine_state { Halted, Start, Inactive, Active, Primed };
    9696
    9797        struct coroutine_desc {
Note: See TracChangeset for help on using the changeset viewer.