Ignore:
Timestamp:
Oct 29, 2019, 4:01:24 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
773db65, 9421f3d8
Parents:
7951100 (diff), 8364209 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 moved

Legend:

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

    r7951100 rb067d9b  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 19 08:23:21 2018
    13 // Update Count     : 31
    14 //
    15 
    16 #include "bits/containers.h"
    17 #include "bits/defs.h"
    18 #include "bits/locks.h"
     12// Last Modified On : Sat Jun 22 18:19:13 2019
     13// Update Count     : 40
     14//
     15
     16#include "bits/containers.hfa"
     17#include "bits/defs.hfa"
     18#include "bits/locks.hfa"
    1919
    2020#ifdef __cforall
     
    4646        #ifdef __cforall
    4747        extern "Cforall" {
    48                 static inline struct thread_desc             * & get_next( struct thread_desc             & this );
    49                 static inline struct __condition_criterion_t * & get_next( struct __condition_criterion_t & this );
    50 
    5148                extern thread_local struct KernelThreadData {
    52                         struct coroutine_desc * volatile this_coroutine;
    5349                        struct thread_desc    * volatile this_thread;
    5450                        struct processor      * volatile this_processor;
     
    5955                                volatile bool in_progress;
    6056                        } preemption_state;
    61                 } kernelTLS;
     57                } kernelTLS __attribute__ ((tls_model ( "initial-exec" )));
    6258        }
    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
    6759        #endif
    6860
    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
     61        struct __stack_context_t {
     62                void * SP;
     63                void * FP;
     64        };
     65
     66        // low adresses  :           +----------------------+ <- start of allocation
     67        //                           |  optional guard page |
     68        //                           +----------------------+ <- __stack_t.limit
     69        //                           |                      |
     70        //                           |       /\ /\ /\       |
     71        //                           |       || || ||       |
     72        //                           |                      |
     73        //                           |    program  stack    |
     74        //                           |                      |
     75        // __stack_info_t.storage -> +----------------------+ <- __stack_t.base
     76        //                           |      __stack_t       |
     77        // high adresses :           +----------------------+ <- end of allocation
     78
     79        struct __stack_t {
     80                // stack grows towards stack limit
     81                void * limit;
     82
     83                // base of stack
     84                void * base;
     85        };
     86
     87        struct __stack_info_t {
     88                // pointer to stack
     89                struct __stack_t * storage;
    7790        };
    7891
     
    8093
    8194        struct coroutine_desc {
    82                 struct coStack_t stack;                                                 // stack information of the coroutine
    83                 const char * name;                                                              // textual name for coroutine/task, initialized by uC++ generated code
    84                 int errno_;                                                                             // copy of global UNIX variable errno
    85                 enum coroutine_state state;                                             // current execution status for coroutine
    86                 struct coroutine_desc * starter;                                // first coroutine to resume this one
    87                 struct coroutine_desc * last;                                   // last coroutine to resume this one
    88         };
    89 
     95                // context that is switch during a CtxSwitch
     96                struct __stack_context_t context;
     97
     98                // stack information of the coroutine
     99                struct __stack_info_t stack;
     100
     101                // textual name for coroutine/task
     102                const char * name;
     103
     104                // current execution status for coroutine
     105                enum coroutine_state state;
     106
     107                // first coroutine to resume this one
     108                struct coroutine_desc * starter;
     109
     110                // last coroutine to resume this one
     111                struct coroutine_desc * last;
     112
     113                // If non-null stack must be unwound with this exception
     114                struct _Unwind_Exception * cancellation;
     115
     116        };
     117
     118        // struct which calls the monitor is accepting
    90119        struct __waitfor_mask_t {
    91120                // the index of the accepted function, -1 if none
     
    93122
    94123                // list of acceptable functions, null if any
    95                 __small_array_t(struct __acceptable_t) __cfa_anonymous_object;
     124                __cfa_anonymous_object( __small_array_t(struct __acceptable_t) );
    96125        };
    97126
     
    121150        struct __monitor_group_t {
    122151                // currently held monitors
    123                 __small_array_t(monitor_desc*) __cfa_anonymous_object;
     152                __cfa_anonymous_object( __small_array_t(monitor_desc*) );
    124153
    125154                // last function that acquired monitors
     
    129158        struct thread_desc {
    130159                // Core threading fields
     160                // context that is switch during a CtxSwitch
     161                struct __stack_context_t context;
     162
     163                // current execution status for coroutine
     164                enum coroutine_state state;
     165
     166                //SKULLDUGGERY errno is not save in the thread data structure because returnToKernel appears to be the only function to require saving and restoring it
     167
    131168                // coroutine body used to store context
    132169                struct coroutine_desc  self_cor;
     
    155192                        struct thread_desc * prev;
    156193                } node;
    157      };
    158 
    159      #ifdef __cforall
    160      extern "Cforall" {
    161                 static inline thread_desc * & get_next( thread_desc & this ) {
     194        };
     195
     196        #ifdef __cforall
     197        extern "Cforall" {
     198                static inline thread_desc *& get_next( thread_desc & this ) {
    162199                        return this.next;
    163200                }
     
    166203                        return this.node.[next, prev];
    167204                }
    168 
    169                 static inline struct __condition_criterion_t * & get_next( struct __condition_criterion_t & this );
    170205
    171206                static inline void ?{}(__monitor_group_t & this) {
     
    216251        // assembler routines that performs the context switch
    217252        extern void CtxInvokeStub( void );
    218         void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
    219 
    220         #if   defined( __i386 )
    221         #define CtxGet( ctx ) __asm__ ( \
    222                         "movl %%esp,%0\n"   \
    223                         "movl %%ebp,%1\n"   \
    224                 : "=rm" (ctx.SP), "=rm" (ctx.FP) )
    225         #elif defined( __x86_64 )
    226         #define CtxGet( ctx ) __asm__ ( \
    227                         "movq %%rsp,%0\n"   \
    228                         "movq %%rbp,%1\n"   \
    229                 : "=rm" (ctx.SP), "=rm" (ctx.FP) )
    230         #elif defined( __ARM_ARCH )
    231         #define CtxGet( ctx ) __asm__ ( \
    232                         "mov %0,%%sp\n"   \
    233                         "mov %1,%%r11\n"   \
    234                 : "=rm" (ctx.SP), "=rm" (ctx.FP) )
    235         #else
    236                 #error unknown hardware architecture
    237         #endif
     253        extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch");
     254        // void CtxStore ( void * this ) asm ("CtxStore");
     255        // void CtxRet   ( void * dst  ) asm ("CtxRet");
    238256
    239257#endif //_INVOKE_PRIVATE_H_
Note: See TracChangeset for help on using the changeset viewer.