Ignore:
File:
1 edited

Legend:

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

    r212c2187 r5b11c25  
    6262        #endif
    6363
    64         struct coStack_t {
    65                 size_t size;                                                                    // size of stack
    66                 void * storage;                                                                 // pointer to stack
    67                 void * limit;                                                                   // stack grows towards stack limit
    68                 void * base;                                                                    // base of stack
    69                 void * context;                                                                 // address of cfa_context_t
    70                 void * top;                                                                             // address of top of storage
    71                 bool userStack;                                                                 // whether or not the user allocated the stack
    72         };
    73 
    74         enum coroutine_state { Halted, Start, Inactive, Active, Primed };
     64        struct __stack_context_t {
     65                void * SP;
     66                void * FP;
     67        };
     68
     69        // low adresses  :           +----------------------+ <- start of allocation
     70        //                           |  optional guard page |
     71        //                           +----------------------+ <- __stack_t.limit
     72        //                           |                      |
     73        //                           |       /\ /\ /\       |
     74        //                           |       || || ||       |
     75        //                           |                      |
     76        //                           |    program  stack    |
     77        //                           |                      |
     78        // __stack_info_t.storage -> +----------------------+ <- __stack_t.base
     79        //                           |      __stack_t       |
     80        // high adresses :           +----------------------+ <- end of allocation
     81
     82        struct __stack_t {
     83                // stack grows towards stack limit
     84                void * limit;
     85
     86                // base of stack
     87                void * base;
     88        };
     89
     90        struct __stack_info_t {
     91                // pointer to stack
     92                struct __stack_t * storage;
     93        };
     94
     95        enum coroutine_state { Halted, Start, Inactive, Active, Primed, PreInactive };
    7596
    7697        struct coroutine_desc {
     98                // context that is switch during a CtxSwitch
     99                struct __stack_context_t context;
     100
    77101                // stack information of the coroutine
    78                 struct coStack_t stack;
    79 
    80                 // textual name for coroutine/task, initialized by uC++ generated code
     102                struct __stack_info_t stack;
     103
     104                // textual name for coroutine/task
    81105                const char * name;
    82 
    83                 // copy of global UNIX variable errno
    84                 int errno_;
    85106
    86107                // current execution status for coroutine
    87108                enum coroutine_state state;
     109
    88110                // first coroutine to resume this one
    89111                struct coroutine_desc * starter;
     
    139161        struct thread_desc {
    140162                // Core threading fields
     163                // context that is switch during a CtxSwitch
     164                struct __stack_context_t context;
     165
     166                // current execution status for coroutine
     167                enum coroutine_state state;
     168
     169                //SKULLDUGGERY errno is not save in the thread data structure because returnToKernel appears to be the only function to require saving and restoring it
     170
    141171                // coroutine body used to store context
    142172                struct coroutine_desc  self_cor;
     
    169199        #ifdef __cforall
    170200        extern "Cforall" {
    171                 static inline struct coroutine_desc * volatile active_coroutine() { return TL_GET( this_thread )->curr_cor; }
    172                 static inline struct thread_desc    * volatile active_thread   () { return TL_GET( this_thread    ); }
    173                 static inline struct processor      * volatile active_processor() { return TL_GET( this_processor ); } // UNSAFE
     201                static inline struct coroutine_desc * active_coroutine() { return TL_GET( this_thread )->curr_cor; }
     202                static inline struct thread_desc    * active_thread   () { return TL_GET( this_thread    ); }
     203                static inline struct processor      * active_processor() { return TL_GET( this_processor ); } // UNSAFE
    174204
    175205                static inline thread_desc * & get_next( thread_desc & this ) {
     
    230260        // assembler routines that performs the context switch
    231261        extern void CtxInvokeStub( void );
    232         void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
     262        extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch");
    233263        // void CtxStore ( void * this ) asm ("CtxStore");
    234264        // void CtxRet   ( void * dst  ) asm ("CtxRet");
    235 
    236         #if   defined( __i386 )
    237         #define CtxGet( ctx ) __asm__ ( \
    238                         "movl %%esp,%0\n"   \
    239                         "movl %%ebp,%1\n"   \
    240                 : "=rm" (ctx.SP), "=rm" (ctx.FP) )
    241         #elif defined( __x86_64 )
    242         #define CtxGet( ctx ) __asm__ ( \
    243                         "movq %%rsp,%0\n"   \
    244                         "movq %%rbp,%1\n"   \
    245                 : "=rm" (ctx.SP), "=rm" (ctx.FP) )
    246         #elif defined( __ARM_ARCH )
    247         #define CtxGet( ctx ) __asm__ ( \
    248                         "mov %0,%%sp\n"   \
    249                         "mov %1,%%r11\n"   \
    250                 : "=rm" (ctx.SP), "=rm" (ctx.FP) )
    251         #else
    252                 #error unknown hardware architecture
    253         #endif
    254265
    255266#endif //_INVOKE_PRIVATE_H_
Note: See TracChangeset for help on using the changeset viewer.