Ignore:
Timestamp:
Jan 7, 2021, 2:55:57 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
58fe85a
Parents:
bdfc032 (diff), 44e37ef (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 dkobets-vector

File:
1 edited

Legend:

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

    rbdfc032 reef8dfb  
    1717#include "bits/defs.hfa"
    1818#include "bits/locks.hfa"
     19#include "kernel/fwd.hfa"
    1920
    2021#ifdef __cforall
     
    2627#define _INVOKE_H_
    2728
    28 #ifdef __ARM_ARCH
    29         // function prototypes are only really used by these macros on ARM
    30         void disable_global_interrupts();
    31         void enable_global_interrupts();
    32 
    33         #define TL_GET( member ) ( { __typeof__( kernelTLS.member ) target; \
    34                 disable_global_interrupts(); \
    35                 target = kernelTLS.member; \
    36                 enable_global_interrupts(); \
    37                 target; } )
    38         #define TL_SET( member, value ) disable_global_interrupts(); \
    39                 kernelTLS.member = value; \
    40                 enable_global_interrupts();
    41 #else
    42         #define TL_GET( member ) kernelTLS.member
    43         #define TL_SET( member, value ) kernelTLS.member = value;
    44 #endif
    45 
    46         #ifdef __cforall
    47         extern "Cforall" {
    48                 extern __attribute__((aligned(128))) thread_local struct KernelThreadData {
    49                         struct thread_desc    * volatile this_thread;
    50                         struct processor      * volatile this_processor;
    51 
    52                         struct {
    53                                 volatile unsigned short disable_count;
    54                                 volatile bool enabled;
    55                                 volatile bool in_progress;
    56                         } preemption_state;
    57 
    58                         uint32_t rand_seed;
    59                 } kernelTLS __attribute__ ((tls_model ( "initial-exec" )));
    60         }
    61         #endif
     29        struct __cfaehm_try_resume_node;
     30        struct __cfaehm_base_exception_t;
     31        struct exception_context_t {
     32                struct __cfaehm_try_resume_node * top_resume;
     33                struct __cfaehm_base_exception_t * current_exception;
     34        };
    6235
    6336        struct __stack_context_t {
     
    8558                // base of stack
    8659                void * base;
     60
     61                // Information for exception handling.
     62                struct exception_context_t exception_context;
    8763        };
    8864
     
    9268        };
    9369
    94         enum coroutine_state { Halted, Start, Inactive, Active, Primed };
    95 
    96         struct coroutine_desc {
    97                 // context that is switch during a CtxSwitch
     70        enum __Coroutine_State { Halted, Start, Primed, Blocked, Ready, Active, Cancelled, Halting };
     71
     72        struct $coroutine {
     73                // context that is switch during a __cfactx_switch
    9874                struct __stack_context_t context;
    9975
     
    10581
    10682                // current execution status for coroutine
    107                 enum coroutine_state state;
     83                enum __Coroutine_State state;
    10884
    10985                // first coroutine to resume this one
    110                 struct coroutine_desc * starter;
     86                struct $coroutine * starter;
    11187
    11288                // last coroutine to resume this one
    113                 struct coroutine_desc * last;
     89                struct $coroutine * last;
    11490
    11591                // If non-null stack must be unwound with this exception
     
    11793
    11894        };
     95        // Wrapper for gdb
     96        struct cfathread_coroutine_t { struct $coroutine debug; };
     97
     98        static inline struct __stack_t * __get_stack( struct $coroutine * cor ) {
     99                return (struct __stack_t*)(((uintptr_t)cor->stack.storage) & ((uintptr_t)-2));
     100        }
    119101
    120102        // struct which calls the monitor is accepting
     
    127109        };
    128110
    129         struct monitor_desc {
     111        struct $monitor {
    130112                // spinlock to protect internal data
    131113                struct __spinlock_t lock;
    132114
    133115                // current owner of the monitor
    134                 struct thread_desc * owner;
     116                struct $thread * owner;
    135117
    136118                // queue of threads that are blocked waiting for the monitor
    137                 __queue_t(struct thread_desc) entry_queue;
     119                __queue_t(struct $thread) entry_queue;
    138120
    139121                // stack of conditions to run next once we exit the monitor
     
    149131                struct __condition_node_t * dtor_node;
    150132        };
     133        // Wrapper for gdb
     134        struct cfathread_monitor_t { struct $monitor debug; };
    151135
    152136        struct __monitor_group_t {
    153137                // currently held monitors
    154                 __cfa_anonymous_object( __small_array_t(monitor_desc*) );
     138                __cfa_anonymous_object( __small_array_t($monitor*) );
    155139
    156140                // last function that acquired monitors
     
    158142        };
    159143
    160         struct thread_desc {
     144        // Link lists fields
     145        // instrusive link field for threads
     146        struct __thread_desc_link {
     147                struct $thread * next;
     148                struct $thread * prev;
     149                volatile unsigned long long ts;
     150                int preferred;
     151        };
     152
     153        struct $thread {
    161154                // Core threading fields
    162                 // context that is switch during a CtxSwitch
     155                // context that is switch during a __cfactx_switch
    163156                struct __stack_context_t context;
    164157
    165158                // current execution status for coroutine
    166                 enum coroutine_state state;
     159                // Possible values are:
     160                //    - TICKET_BLOCKED (-1) thread is blocked
     161                //    - TICKET_RUNNING ( 0) thread is running
     162                //    - TICKET_UNBLOCK ( 1) thread should ignore next block
     163                volatile int ticket;
     164                enum __Coroutine_State state:8;
     165                enum __Preemption_Reason preempted:8;
    167166
    168167                //SKULLDUGGERY errno is not save in the thread data structure because returnToKernel appears to be the only function to require saving and restoring it
    169 
    170                 // coroutine body used to store context
    171                 struct coroutine_desc  self_cor;
    172 
    173                 // current active context
    174                 struct coroutine_desc * curr_cor;
    175 
    176                 // monitor body used for mutual exclusion
    177                 struct monitor_desc    self_mon;
    178 
    179                 // pointer to monitor with sufficient lifetime for current monitors
    180                 struct monitor_desc *  self_mon_p;
    181168
    182169                // pointer to the cluster on which the thread is running
    183170                struct cluster * curr_cluster;
    184171
     172                // Link lists fields
     173                // instrusive link field for threads
     174                struct __thread_desc_link link;
     175
     176                // coroutine body used to store context
     177                struct $coroutine  self_cor;
     178
     179                // current active context
     180                struct $coroutine * curr_cor;
     181
     182                // monitor body used for mutual exclusion
     183                struct $monitor    self_mon;
     184
     185                // pointer to monitor with sufficient lifetime for current monitors
     186                struct $monitor *  self_mon_p;
     187
    185188                // monitors currently held by this thread
    186189                struct __monitor_group_t monitors;
    187190
    188                 // Link lists fields
    189                 // instrusive link field for threads
    190                 struct thread_desc * next;
    191 
     191                // used to put threads on user data structures
    192192                struct {
    193                         struct thread_desc * next;
    194                         struct thread_desc * prev;
     193                        struct $thread * next;
     194                        struct $thread * back;
     195                } seqable;
     196
     197                struct {
     198                        struct $thread * next;
     199                        struct $thread * prev;
    195200                } node;
    196         };
     201
     202                #if defined( __CFA_WITH_VERIFY__ )
     203                        void * canary;
     204                #endif
     205        };
     206        // Wrapper for gdb
     207        struct cfathread_thread_t { struct $thread debug; };
     208
     209        #ifdef __CFA_DEBUG__
     210                void __cfaabi_dbg_record_thrd($thread & this, bool park, const char prev_name[]);
     211        #else
     212                #define __cfaabi_dbg_record_thrd(x, y, z)
     213        #endif
    197214
    198215        #ifdef __cforall
    199216        extern "Cforall" {
    200                 static inline thread_desc *& get_next( thread_desc & this ) {
    201                         return this.next;
    202                 }
    203 
    204                 static inline [thread_desc *&, thread_desc *& ] __get( thread_desc & this ) {
     217
     218                static inline $thread *& get_next( $thread & this ) __attribute__((const)) {
     219                        return this.link.next;
     220                }
     221
     222                static inline [$thread *&, $thread *& ] __get( $thread & this ) __attribute__((const)) {
    205223                        return this.node.[next, prev];
     224                }
     225
     226                static inline $thread *& Back( $thread * this ) __attribute__((const)) {
     227                        return this->seqable.back;
     228                }
     229
     230                static inline $thread *& Next( $thread * this ) __attribute__((const)) {
     231                        return this->seqable.next;
     232                }
     233
     234                static inline bool listed( $thread * this ) {
     235                        return this->seqable.next != 0p;
    206236                }
    207237
     
    212242                }
    213243
    214                 static inline void ?{}(__monitor_group_t & this, struct monitor_desc ** data, __lock_size_t size, fptr_t func) {
     244                static inline void ?{}(__monitor_group_t & this, struct $monitor ** data, __lock_size_t size, fptr_t func) {
    215245                        (this.data){data};
    216246                        (this.size){size};
     
    218248                }
    219249
    220                 static inline bool ?==?( const __monitor_group_t & lhs, const __monitor_group_t & rhs ) {
     250                static inline bool ?==?( const __monitor_group_t & lhs, const __monitor_group_t & rhs ) __attribute__((const)) {
    221251                        if( (lhs.data != 0) != (rhs.data != 0) ) return false;
    222252                        if( lhs.size != rhs.size ) return false;
     
    252282
    253283        // assembler routines that performs the context switch
    254         extern void CtxInvokeStub( void );
    255         extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch");
     284        extern void __cfactx_invoke_stub( void );
     285        extern void __cfactx_switch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("__cfactx_switch");
    256286        // void CtxStore ( void * this ) asm ("CtxStore");
    257287        // void CtxRet   ( void * dst  ) asm ("CtxRet");
Note: See TracChangeset for help on using the changeset viewer.