Ignore:
Timestamp:
Dec 6, 2016, 4:16:47 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:
fa66f4e
Parents:
e4745d7a
Message:

Implemented coroutine for i386 and added coroutines to tests

Location:
src/libcfa/concurrency
Files:
2 edited

Legend:

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

    re4745d7a rd9c44c3  
    44#include <stdio.h>
    55
     6#include "libhdr.h"
    67#include "invoke.h"
    78
     
    1819void __invokeCoroutine__F_P9scoVtablePv__1(struct coVtable *vtable, void* vthis)
    1920{
    20       printf("Invoke : Received %p (v %p)\n", vthis, vtable);
     21      LIB_DEBUG_PRINTF("Invoke : Received %p (v %p)\n", vthis, vtable);
    2122
    2223      struct coroutine* cor = vtable->this_coroutine(vthis);
     
    3435      void (*invoke)(struct coVtable *, void *)
    3536) {
    36 
    37       #if ! defined( __x86_64__ ) && ! defined( __i386__ )
    38             #error Only __x86_64__ and __i386__ is supported for threads in cfa
    39       #endif
    40 
    41       #if defined( __U_SWAPCONTEXT__ )
    42             #error __U_SWAPCONTEXT__ should not be defined for __x86_64__
    43       #endif
     37      LIB_DEBUG_PRINTF("StartCoroutine : Passing in %p (v %p) to %p\n", vthis, vtable, invoke);
    4438
    4539      struct coVtable * vtable = get_vtable( vthis );
     
    4741      struct coStack_t* stack = &this->stack;
    4842
     43#if defined( __i386__ )
     44
     45        struct FakeStack {
     46            void *fixedRegisters[3];                    // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant)
     47            void *rturn;                                      // where to go on return from uSwitch
     48            void *dummyReturn;                          // fake return compiler would have pushed on call to uInvoke
     49            void *argument[2];                          // for 16-byte ABI, 16-byte alignment starts here
     50            void *padding[2];                           // padding to force 16-byte alignment, as "base" is 16-byte aligned
     51        };
     52
     53        ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );
     54        ((struct machine_context_t *)stack->context)->FP = NULL;                // terminate stack with NULL fp
     55
     56        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL;
     57        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = vtable; // argument to invoke
     58      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[1] = vthis;  // argument to invoke
     59        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke;
     60
     61#elif defined( __x86_64__ )
     62
    4963      struct FakeStack {
    5064            void *fixedRegisters[5];                    // fixed registers rbx, r12, r13, r14, r15
    5165            void *rturn;                                        // where to go on return from uSwitch
    5266            void *dummyReturn;                          // NULL return address to provide proper alignment
    53       }; // FakeStack
     67      };
    5468
    5569      ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack );
    5670      ((struct machine_context_t *)stack->context)->FP = NULL;          // terminate stack with NULL fp
    57 
    58       fprintf(stderr, "StartCoroutine : Passing in %p (v %p) to %p\n", vthis, vtable, invoke);
    5971
    6072      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL;
     
    6375      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = vthis;
    6476      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[2] = invoke;
     77#else
     78      #error Only __i386__ and __x86_64__ is supported for threads in cfa
     79#endif
    6580}
  • src/libcfa/concurrency/threads.c

    re4745d7a rd9c44c3  
    166166        coroutine* dst = this_coroutine(cor);
    167167
    168         fprintf(stderr, "Resuming %p from %p\n", dst, src);
    169168        if ( src != dst ) {                             // not resuming self ?
    170169                assertf( dst->notHalted ,
     
    172171                        "Possible cause is terminated coroutine's main routine has already returned.",
    173172                        src->name, src, dst->name, dst );
    174                 fprintf(stderr, "Assigning last pointer\n");
    175173                dst->last = src;                                        // set last resumer
    176174        } // if
Note: See TracChangeset for help on using the changeset viewer.