Ignore:
Timestamp:
May 11, 2020, 1:53:29 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
504a7dc
Parents:
b7d6a36 (diff), a7b486b (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' into relaxed_ready

File:
1 edited

Legend:

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

    rb7d6a36 r6a490b2  
    4747        extern "Cforall" {
    4848                extern __attribute__((aligned(128))) thread_local struct KernelThreadData {
    49                         struct thread_desc    * volatile this_thread;
     49                        struct $thread    * volatile this_thread;
    5050                        struct processor      * volatile this_processor;
    5151
     
    9292        };
    9393
    94         enum coroutine_state { Halted, Start, Inactive, Active, Primed };
    95 
    96         struct coroutine_desc {
    97                 // context that is switch during a CtxSwitch
     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
    9899                struct __stack_context_t context;
    99100
     
    108109
    109110                // first coroutine to resume this one
    110                 struct coroutine_desc * starter;
     111                struct $coroutine * starter;
    111112
    112113                // last coroutine to resume this one
    113                 struct coroutine_desc * last;
     114                struct $coroutine * last;
    114115
    115116                // If non-null stack must be unwound with this exception
     
    117118
    118119        };
     120
     121        static inline struct __stack_t * __get_stack( struct $coroutine * cor ) { return (struct __stack_t*)(((uintptr_t)cor->stack.storage) & ((uintptr_t)-2)); }
    119122
    120123        // struct which calls the monitor is accepting
     
    127130        };
    128131
    129         struct monitor_desc {
     132        struct $monitor {
    130133                // spinlock to protect internal data
    131134                struct __spinlock_t lock;
    132135
    133136                // current owner of the monitor
    134                 struct thread_desc * owner;
     137                struct $thread * owner;
    135138
    136139                // queue of threads that are blocked waiting for the monitor
    137                 __queue_t(struct thread_desc) entry_queue;
     140                __queue_t(struct $thread) entry_queue;
    138141
    139142                // stack of conditions to run next once we exit the monitor
     
    152155        struct __monitor_group_t {
    153156                // currently held monitors
    154                 __cfa_anonymous_object( __small_array_t(monitor_desc*) );
     157                __cfa_anonymous_object( __small_array_t($monitor*) );
    155158
    156159                // last function that acquired monitors
     
    161164        // instrusive link field for threads
    162165        struct __thread_desc_link {
    163                 struct thread_desc * next;
    164                 struct thread_desc * prev;
     166                struct $thread * next;
     167                struct $thread * prev;
    165168                unsigned long long ts;
    166169        };
    167170
    168         struct thread_desc {
     171        struct $thread {
    169172                // Core threading fields
    170                 // context that is switch during a CtxSwitch
     173                // context that is switch during a __cfactx_switch
    171174                struct __stack_context_t context;
    172175
    173176                // current execution status for coroutine
    174                 enum coroutine_state state;
     177                volatile int state;
     178                enum __Preemption_Reason preempted;
    175179
    176180                //SKULLDUGGERY errno is not save in the thread data structure because returnToKernel appears to be the only function to require saving and restoring it
    177181
    178182                // coroutine body used to store context
    179                 struct coroutine_desc  self_cor;
     183                struct $coroutine  self_cor;
    180184
    181185                // current active context
    182                 struct coroutine_desc * curr_cor;
     186                struct $coroutine * curr_cor;
    183187
    184188                // monitor body used for mutual exclusion
    185                 struct monitor_desc    self_mon;
     189                struct $monitor    self_mon;
    186190
    187191                // pointer to monitor with sufficient lifetime for current monitors
    188                 struct monitor_desc *  self_mon_p;
     192                struct $monitor *  self_mon_p;
    189193
    190194                // pointer to the cluster on which the thread is running
     
    199203
    200204                struct {
    201                         struct thread_desc * next;
    202                         struct thread_desc * prev;
     205                        struct $thread * next;
     206                        struct $thread * prev;
    203207                } node;
    204         };
     208
     209                #ifdef __CFA_DEBUG__
     210                        // previous function to park/unpark the thread
     211                        const char * park_caller;
     212                        enum coroutine_state park_result;
     213                        bool park_stale;
     214                        const char * unpark_caller;
     215                        enum coroutine_state unpark_result;
     216                        bool unpark_stale;
     217                #endif
     218        };
     219
     220        #ifdef __CFA_DEBUG__
     221                void __cfaabi_dbg_record_thrd($thread & this, bool park, const char prev_name[]);
     222        #else
     223                #define __cfaabi_dbg_record_thrd(x, y, z)
     224        #endif
    205225
    206226        #ifdef __cforall
    207227        extern "Cforall" {
    208                 static inline thread_desc *& get_next( thread_desc & this ) {
     228
     229                static inline $thread *& get_next( $thread & this ) __attribute__((const)) {
    209230                        return this.link.next;
    210231                }
    211232
    212                 static inline [thread_desc *&, thread_desc *& ] __get( thread_desc & this ) {
     233                static inline [$thread *&, $thread *& ] __get( $thread & this ) __attribute__((const)) {
    213234                        return this.node.[next, prev];
    214235                }
     
    220241                }
    221242
    222                 static inline void ?{}(__monitor_group_t & this, struct monitor_desc ** data, __lock_size_t size, fptr_t func) {
     243                static inline void ?{}(__monitor_group_t & this, struct $monitor ** data, __lock_size_t size, fptr_t func) {
    223244                        (this.data){data};
    224245                        (this.size){size};
     
    226247                }
    227248
    228                 static inline bool ?==?( const __monitor_group_t & lhs, const __monitor_group_t & rhs ) {
     249                static inline bool ?==?( const __monitor_group_t & lhs, const __monitor_group_t & rhs ) __attribute__((const)) {
    229250                        if( (lhs.data != 0) != (rhs.data != 0) ) return false;
    230251                        if( lhs.size != rhs.size ) return false;
     
    260281
    261282        // assembler routines that performs the context switch
    262         extern void CtxInvokeStub( void );
    263         extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch");
     283        extern void __cfactx_invoke_stub( void );
     284        extern void __cfactx_switch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("__cfactx_switch");
    264285        // void CtxStore ( void * this ) asm ("CtxStore");
    265286        // void CtxRet   ( void * dst  ) asm ("CtxRet");
Note: See TracChangeset for help on using the changeset viewer.