Ignore:
File:
1 edited

Legend:

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

    r5c81105 r78b3f52  
    1 #include <stdbool.h>
    2 #include <stdint.h>
    31
    4 #ifdef __CFORALL__
    5 extern "C" {
    6 #endif
    7 
    8 #if ! defined(__CFA_INVOKE_PRIVATE__)
    92#ifndef _INVOKE_H_
    103#define _INVOKE_H_
    114
    12       #define OFFSET_OF(type, field) ((intptr_t)( &((type*)0)->field))
    13       #define VPTR_OFFSET(type, vptr, field) (OFFSET_OF(type, field) - OFFSET_OF(type, vptr))
     5struct coVtable {
     6      void (*main)(void*);
     7      struct coroutine* (*this_coroutine)(void*);
     8};
    149
    15       struct coVtable_t {
    16             void (*main)(void*);
    17             intptr_t offset_coroutine;
    18             intptr_t offset_object;
    19       };
     10struct coStack_t {
     11      unsigned int size;                // size of stack
     12      void *storage;                    // pointer to stack
     13      void *limit;                      // stack grows towards stack limit
     14      void *base;                               // base of stack
     15      void *context;                    // address of cfa_context_t
     16      void *top;                                // address of top of storage
     17      bool userStack;   
     18};
    2019
    21       typedef struct coVtable_t* covptr_t;
    2220
    23       static inline struct coroutine* get_coroutine(covptr_t* vthis) {
    24             return (struct coroutine*) ( ((intptr_t)vthis) + ((intptr_t)(*vthis)->offset_coroutine) );
    25       }
     21enum coroutine_state { Start, Inactive, Active, Halt };
    2622
    27       static inline void* get_object(covptr_t* vthis) {
    28             return (void*) ( ((intptr_t)vthis) + ((intptr_t)(*vthis)->offset_object) );
    29       }
     23struct coroutine {
     24      struct coStack_t stack;
     25      const char *name;                 // textual name for coroutine/task, initialized by uC++ generated code
     26      int errno_;                               // copy of global UNIX variable errno
     27      enum coroutine_state state;             // current execution status for coroutine
     28      bool notHalted;                   // indicate if execuation state is not halted
    3029
    31       struct coStack_t {
    32             unsigned int size;          // size of stack
    33             void *storage;                      // pointer to stack
    34             void *limit;                        // stack grows towards stack limit
    35             void *base;                         // base of stack
    36             void *context;                      // address of cfa_context_t
    37             void *top;                          // address of top of storage
    38             bool userStack;     
    39       };
     30      struct coroutine *starter;                // first coroutine to resume this one
     31      struct coroutine *last;                   // last coroutine to resume this one
     32};
    4033
    41       enum coroutine_state { Start, Inactive, Active, Halt };
    42 
    43       struct coroutine {
    44             struct coStack_t stack;
    45             const char *name;                   // textual name for coroutine/task, initialized by uC++ generated code
    46             int errno_;                         // copy of global UNIX variable errno
    47             enum coroutine_state state; // current execution status for coroutine
    48             bool notHalted;                     // indicate if execuation state is not halted
    49 
    50             struct coroutine *starter;  // first coroutine to resume this one
    51             struct coroutine *last;             // last coroutine to resume this one
    52       };
    53 
    54       void invokeCoroutine(covptr_t* this);
    55       void startCoroutine(covptr_t* this, void (*invoke)(covptr_t*));
    5634#endif //_INVOKE_H_
    57 #else //! defined(__CFA_INVOKE_PRIVATE__)
    58 #ifndef _INVOKE_PRIVATE_H_
    59 #define _INVOKE_PRIVATE_H_
    60      
    61      struct machine_context_t {
    62             void *SP;
    63             void *FP;
    64             void *PC;
    65       };
    66 
    67       // assembler routines that performs the context switch
    68       extern void coInvokeStub( void );
    69       void CtxSwitch( void *from, void *to ) asm ("CtxSwitch");
    70 
    71 #endif //_INVOKE_PRIVATE_H_
    72 #endif //! defined(__CFA_INVOKE_PRIVATE__)
    73 #ifdef __CFORALL__
    74 }
    75 #endif
Note: See TracChangeset for help on using the changeset viewer.