Ignore:
File:
1 edited

Legend:

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

    rae7be7a rb798713  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec  5 16:26:03 2019
    13 // Update Count     : 44
     12// Last Modified On : Sat Jun 22 18:19:13 2019
     13// Update Count     : 40
    1414//
    1515
     
    4747        extern "Cforall" {
    4848                extern __attribute__((aligned(128))) thread_local struct KernelThreadData {
    49                         struct $thread    * volatile this_thread;
     49                        struct thread_desc    * volatile this_thread;
    5050                        struct processor      * volatile this_processor;
    5151
     
    9292        };
    9393
    94         enum coroutine_state { Halted, Start, Primed, Blocked, Ready, Active, Rerun };
    95         enum __Preemption_Reason { __NO_PREEMPTION, __ALARM_PREEMPTION, __POLL_PREEMPTION, __MANUAL_PREEMPTION };
    96 
    97         struct $coroutine {
    98                 // context that is switch during a __cfactx_switch
     94        enum coroutine_state { Halted, Start, Inactive, Active, Primed };
     95
     96        struct coroutine_desc {
     97                // context that is switch during a CtxSwitch
    9998                struct __stack_context_t context;
    10099
     
    109108
    110109                // first coroutine to resume this one
    111                 struct $coroutine * starter;
     110                struct coroutine_desc * starter;
    112111
    113112                // last coroutine to resume this one
    114                 struct $coroutine * last;
     113                struct coroutine_desc * last;
    115114
    116115                // If non-null stack must be unwound with this exception
     
    118117
    119118        };
    120 
    121         static inline struct __stack_t * __get_stack( struct $coroutine * cor ) { return (struct __stack_t*)(((uintptr_t)cor->stack.storage) & ((uintptr_t)-2)); }
    122119
    123120        // struct which calls the monitor is accepting
     
    130127        };
    131128
    132         struct $monitor {
     129        struct monitor_desc {
    133130                // spinlock to protect internal data
    134131                struct __spinlock_t lock;
    135132
    136133                // current owner of the monitor
    137                 struct $thread * owner;
     134                struct thread_desc * owner;
    138135
    139136                // queue of threads that are blocked waiting for the monitor
    140                 __queue_t(struct $thread) entry_queue;
     137                __queue_t(struct thread_desc) entry_queue;
    141138
    142139                // stack of conditions to run next once we exit the monitor
     
    155152        struct __monitor_group_t {
    156153                // currently held monitors
    157                 __cfa_anonymous_object( __small_array_t($monitor*) );
     154                __cfa_anonymous_object( __small_array_t(monitor_desc*) );
    158155
    159156                // last function that acquired monitors
     
    161158        };
    162159
    163         struct $thread {
     160        // Link lists fields
     161        // instrusive link field for threads
     162        struct __thread_desc_link {
     163                struct thread_desc * next;
     164                struct thread_desc * prev;
     165                unsigned long long ts;
     166        };
     167
     168        struct thread_desc {
    164169                // Core threading fields
    165                 // context that is switch during a __cfactx_switch
     170                // context that is switch during a CtxSwitch
    166171                struct __stack_context_t context;
    167172
    168173                // current execution status for coroutine
    169                 volatile int state;
    170                 enum __Preemption_Reason preempted;
     174                enum coroutine_state state;
    171175
    172176                //SKULLDUGGERY errno is not save in the thread data structure because returnToKernel appears to be the only function to require saving and restoring it
    173177
    174178                // coroutine body used to store context
    175                 struct $coroutine  self_cor;
     179                struct coroutine_desc  self_cor;
    176180
    177181                // current active context
    178                 struct $coroutine * curr_cor;
     182                struct coroutine_desc * curr_cor;
    179183
    180184                // monitor body used for mutual exclusion
    181                 struct $monitor    self_mon;
     185                struct monitor_desc    self_mon;
    182186
    183187                // pointer to monitor with sufficient lifetime for current monitors
    184                 struct $monitor *  self_mon_p;
     188                struct monitor_desc *  self_mon_p;
    185189
    186190                // pointer to the cluster on which the thread is running
     
    192196                // Link lists fields
    193197                // instrusive link field for threads
    194                 struct $thread * next;
     198                struct __thread_desc_link link;
    195199
    196200                struct {
    197                         struct $thread * next;
    198                         struct $thread * prev;
     201                        struct thread_desc * next;
     202                        struct thread_desc * prev;
    199203                } node;
    200 
    201                 #ifdef __CFA_DEBUG__
    202                         // previous function to park/unpark the thread
    203                         const char * park_caller;
    204                         enum coroutine_state park_result;
    205                         bool park_stale;
    206                         const char * unpark_caller;
    207                         enum coroutine_state unpark_result;
    208                         bool unpark_stale;
    209                 #endif
    210         };
    211 
    212         #ifdef __CFA_DEBUG__
    213                 void __cfaabi_dbg_record_thrd($thread & this, bool park, const char prev_name[]);
    214         #else
    215                 #define __cfaabi_dbg_record_thrd(x, y, z)
    216         #endif
     204        };
    217205
    218206        #ifdef __cforall
    219207        extern "Cforall" {
    220                 static inline $thread *& get_next( $thread & this ) __attribute__((const)) {
    221                         return this.next;
    222                 }
    223 
    224                 static inline [$thread *&, $thread *& ] __get( $thread & this ) __attribute__((const)) {
     208                static inline thread_desc *& get_next( thread_desc & this ) {
     209                        return this.link.next;
     210                }
     211
     212                static inline [thread_desc *&, thread_desc *& ] __get( thread_desc & this ) {
    225213                        return this.node.[next, prev];
    226214                }
    227215
    228216                static inline void ?{}(__monitor_group_t & this) {
    229                         (this.data){0p};
     217                        (this.data){NULL};
    230218                        (this.size){0};
    231219                        (this.func){NULL};
    232220                }
    233221
    234                 static inline void ?{}(__monitor_group_t & this, struct $monitor ** data, __lock_size_t size, fptr_t func) {
     222                static inline void ?{}(__monitor_group_t & this, struct monitor_desc ** data, __lock_size_t size, fptr_t func) {
    235223                        (this.data){data};
    236224                        (this.size){size};
     
    238226                }
    239227
    240                 static inline bool ?==?( const __monitor_group_t & lhs, const __monitor_group_t & rhs ) __attribute__((const)) {
     228                static inline bool ?==?( const __monitor_group_t & lhs, const __monitor_group_t & rhs ) {
    241229                        if( (lhs.data != 0) != (rhs.data != 0) ) return false;
    242230                        if( lhs.size != rhs.size ) return false;
     
    272260
    273261        // assembler routines that performs the context switch
    274         extern void __cfactx_invoke_stub( void );
    275         extern void __cfactx_switch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("__cfactx_switch");
     262        extern void CtxInvokeStub( void );
     263        extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch");
    276264        // void CtxStore ( void * this ) asm ("CtxStore");
    277265        // void CtxRet   ( void * dst  ) asm ("CtxRet");
Note: See TracChangeset for help on using the changeset viewer.