Ignore:
File:
1 edited

Legend:

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

    r1c273d0 rcb0e6de  
    2929
    3030extern void __suspend_internal(void);
    31 extern void __leave_thread_monitor( struct thread_desc * this );
    32 extern void disable_interrupts();
    33 extern void enable_interrupts( const char * );
     31extern void __leave_monitor_desc( struct monitor_desc * this );
    3432
    3533void CtxInvokeCoroutine(
    36       void (*main)(void *),
    37       struct coroutine_desc *(*get_coroutine)(void *),
     34      void (*main)(void *), 
     35      struct coroutine_desc *(*get_coroutine)(void *), 
    3836      void *this
    3937) {
     
    5856
    5957void CtxInvokeThread(
    60       void (*dtor)(void *),
    61       void (*main)(void *),
    62       struct thread_desc *(*get_thread)(void *),
     58      void (*dtor)(void *), 
     59      void (*main)(void *), 
     60      struct thread_desc *(*get_thread)(void *), 
    6361      void *this
    6462) {
    65       // First suspend, once the thread arrives here,
    66       // the function pointer to main can be invalidated without risk
    6763      __suspend_internal();
    6864
    69       // Fetch the thread handle from the user defined thread structure
    7065      struct thread_desc* thrd = get_thread( this );
     66      struct coroutine_desc* cor = &thrd->cor;
     67      struct monitor_desc* mon = &thrd->mon;
     68      cor->state = Active;
    7169
    72       // Officially start the thread by enabling preemption
    73       enable_interrupts( __PRETTY_FUNCTION__ );
    74 
    75       // Call the main of the thread
     70      // LIB_DEBUG_PRINTF("Invoke Thread : invoking main %p (args %p)\n", main, this);
    7671      main( this );
    7772
    78       // To exit a thread we must :
    79       // 1 - Mark it as halted
    80       // 2 - Leave its monitor
    81       // 3 - Disable the interupts
    82       // The order of these 3 operations is very important
    83       __leave_thread_monitor( thrd );
     73      __leave_monitor_desc( mon );
    8474
    8575      //Final suspend, should never return
     
    9080
    9181void CtxStart(
    92       void (*main)(void *),
    93       struct coroutine_desc *(*get_coroutine)(void *),
    94       void *this,
     82      void (*main)(void *), 
     83      struct coroutine_desc *(*get_coroutine)(void *), 
     84      void *this, 
    9585      void (*invoke)(void *)
    9686) {
     
    118108        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke;
    119109      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
    120       ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
     110      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7 
    121111
    122112#elif defined( __x86_64__ )
     
    138128      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = invoke;
    139129      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
    140       ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
     130      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7 
    141131#else
    142132      #error Only __i386__ and __x86_64__ is supported for threads in cfa
Note: See TracChangeset for help on using the changeset viewer.