Ignore:
Timestamp:
Dec 7, 2016, 2:47:53 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
550a3385
Parents:
a68caae
Message:

Coroutines no longer require virtual pointers or any code beyond the get_coroutine routine

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/invoke.c

    ra68caae r80d9e49  
    1313// Called from the kernel when starting a coroutine or task so must switch back to user mode.
    1414
    15 void invokeCoroutine(covptr_t* vthis)
    16 {
    17       LIB_DEBUG_PRINTF("Invoke : Received %p (v %p)\n", vthis, *vthis);
     15extern void __suspend__F___1(void);
    1816
    19       struct coroutine* cor = get_coroutine( vthis );
     17void invokeCoroutine(
     18      void (*main)(void *),
     19      struct coroutine *(*get_coroutine)(void *),
     20      void *this
     21) {
     22      LIB_DEBUG_PRINTF("Invoke : Received %p (main %p, get_c %p)\n", this, main, get_coroutine);
     23
     24      struct coroutine* cor = get_coroutine( this );
     25
     26      if(cor->state == Primed) {
     27            __suspend__F___1();
     28      }
    2029
    2130      cor->state = Active;
    2231
    23       (*vthis)->main( get_object(vthis) );
     32      main( this );
    2433}
    2534
    2635
    27 void startCoroutine(covptr_t* vthis, void (*invoke)(covptr_t*)) {
    28       LIB_DEBUG_PRINTF("StartCoroutine : Passing in %p (v %p) to %p\n", vthis, *vthis, invoke);
     36void startCoroutine(
     37      void (*main)(void *),
     38      struct coroutine *(*get_coroutine)(void *),
     39      void *this,
     40      void (*invoke)(void *)
     41) {
     42      LIB_DEBUG_PRINTF("StartCoroutine : Passing in %p (main %p, get_c %p) to %p\n", this, main, get_coroutine, invoke);
    2943
    30       struct coroutine* this = get_coroutine( vthis );
    31       struct coStack_t* stack = &this->stack;
     44      struct coStack_t* stack = &get_coroutine( this )->stack;
    3245
    3346#if defined( __i386__ )
     
    3750            void *rturn;                                      // where to go on return from uSwitch
    3851            void *dummyReturn;                          // fake return compiler would have pushed on call to uInvoke
    39             void *argument;                             // for 16-byte ABI, 16-byte alignment starts here
    40             void *padding[3];                           // padding to force 16-byte alignment, as "base" is 16-byte aligned
     52            void *argument[3];                          // for 16-byte ABI, 16-byte alignment starts here
     53            void *padding;                              // padding to force 16-byte alignment, as "base" is 16-byte aligned
    4154        };
    4255
     
    4558
    4659        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL;
    47         ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument = vthis;     // argument to invoke
     60        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = this;     // argument to invoke
    4861        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke;
    4962
     
    6174      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL;
    6275      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = coInvokeStub;
    63       ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[0] = vthis;
     76      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[0] = this;
    6477      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = invoke;
    6578#else
Note: See TracChangeset for help on using the changeset viewer.