Ignore:
File:
1 edited

Legend:

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

    r63364d8 r76e069f  
    5050
    5151                extern thread_local struct KernelThreadData {
     52                        struct coroutine_desc * volatile this_coroutine;
    5253                        struct thread_desc    * volatile this_thread;
    5354                        struct processor      * volatile this_processor;
     
    6061                } kernelTLS __attribute__ ((tls_model ( "initial-exec" )));
    6162        }
     63
     64        static inline struct coroutine_desc * volatile active_coroutine() { return TL_GET( this_coroutine ); }
     65        static inline struct thread_desc    * volatile active_thread   () { return TL_GET( this_thread    ); }
     66        static inline struct processor      * volatile active_processor() { return TL_GET( this_processor ); } // UNSAFE
    6267        #endif
    6368
    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;
     69        struct coStack_t {
     70                size_t size;                                                                    // size of stack
     71                void * storage;                                                                 // pointer to stack
     72                void * limit;                                                                   // stack grows towards stack limit
     73                void * base;                                                                    // base of stack
     74                void * context;                                                                 // address of cfa_context_t
     75                void * top;                                                                             // address of top of storage
     76                bool userStack;                                                                 // whether or not the user allocated the stack
    9377        };
    9478
     
    9680
    9781        struct coroutine_desc {
    98                 // context that is switch during a CtxSwitch
    99                 struct __stack_context_t context;
    100 
    10182                // stack information of the coroutine
    102                 struct __stack_info_t stack;
    103 
    104                 // textual name for coroutine/task
     83                struct coStack_t stack;
     84
     85                // textual name for coroutine/task, initialized by uC++ generated code
    10586                const char * name;
     87
     88                // copy of global UNIX variable errno
     89                int errno_;
    10690
    10791                // current execution status for coroutine
    10892                enum coroutine_state state;
    109 
    11093                // first coroutine to resume this one
    11194                struct coroutine_desc * starter;
     
    161144        struct thread_desc {
    162145                // 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 
    171146                // coroutine body used to store context
    172147                struct coroutine_desc  self_cor;
     
    195170                        struct thread_desc * prev;
    196171                } node;
    197         };
    198 
    199         #ifdef __cforall
    200         extern "Cforall" {
    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
    204 
     172     };
     173
     174     #ifdef __cforall
     175     extern "Cforall" {
    205176                static inline thread_desc * & get_next( thread_desc & this ) {
    206177                        return this.next;
     
    260231        // assembler routines that performs the context switch
    261232        extern void CtxInvokeStub( void );
    262         extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch");
    263         // void CtxStore ( void * this ) asm ("CtxStore");
    264         // void CtxRet   ( void * dst  ) asm ("CtxRet");
     233        void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
     234
     235        #if   defined( __i386 )
     236        #define CtxGet( ctx ) __asm__ ( \
     237                        "movl %%esp,%0\n"   \
     238                        "movl %%ebp,%1\n"   \
     239                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     240        #elif defined( __x86_64 )
     241        #define CtxGet( ctx ) __asm__ ( \
     242                        "movq %%rsp,%0\n"   \
     243                        "movq %%rbp,%1\n"   \
     244                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     245        #elif defined( __ARM_ARCH )
     246        #define CtxGet( ctx ) __asm__ ( \
     247                        "mov %0,%%sp\n"   \
     248                        "mov %1,%%r11\n"   \
     249                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     250        #else
     251                #error unknown hardware architecture
     252        #endif
    265253
    266254#endif //_INVOKE_PRIVATE_H_
Note: See TracChangeset for help on using the changeset viewer.