Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b7c89aa
Parents:
f9feab8 (diff), 305581d (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 cleanup-dtors

File:
1 moved

Legend:

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

    rf9feab8 r90152a4  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:28:56 2017
    13 // Update Count     : 1
    14 //
    15 
    16 #include "bits/containers.h"
    17 #include "bits/defs.h"
    18 #include "bits/locks.h"
     12// Last Modified On : Sat May 19 08:23:21 2018
     13// Update Count     : 31
     14//
     15
     16#include "bits/containers.hfa"
     17#include "bits/defs.hfa"
     18#include "bits/locks.hfa"
    1919
    2020#ifdef __cforall
     
    2525#ifndef _INVOKE_H_
    2626#define _INVOKE_H_
     27
     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
    2745
    2846        #ifdef __cforall
     
    3048                static inline struct thread_desc             * & get_next( struct thread_desc             & this );
    3149                static inline struct __condition_criterion_t * & get_next( struct __condition_criterion_t & this );
     50
     51                extern thread_local struct KernelThreadData {
     52                        struct coroutine_desc * volatile this_coroutine;
     53                        struct thread_desc    * volatile this_thread;
     54                        struct processor      * volatile this_processor;
     55
     56                        struct {
     57                                volatile unsigned short disable_count;
     58                                volatile bool enabled;
     59                                volatile bool in_progress;
     60                        } preemption_state;
     61                } kernelTLS;
    3262        }
     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
    3367        #endif
    3468
    3569        struct coStack_t {
    36                 // size of stack
    37                 size_t size;
    38 
    39                 // pointer to stack
    40                 void *storage;
    41 
    42                 // stack grows towards stack limit
    43                 void *limit;
    44 
    45                 // base of stack
    46                 void *base;
    47 
    48                 // address of cfa_context_t
    49                 void *context;
    50 
    51                 // address of top of storage
    52                 void *top;
    53 
    54                 // whether or not the user allocated the stack
    55                 bool userStack;
     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
    5677        };
    5778
     
    5980
    6081        struct coroutine_desc {
    61                 // stack information of the coroutine
    62                 struct coStack_t stack;
    63 
    64                 // textual name for coroutine/task, initialized by uC++ generated code
    65                 const char *name;
    66 
    67                 // copy of global UNIX variable errno
    68                 int errno_;
    69 
    70                 // current execution status for coroutine
    71                 enum coroutine_state state;
    72 
    73                 // first coroutine to resume this one
    74                 struct coroutine_desc * starter;
    75 
    76                 // last coroutine to resume this one
    77                 struct coroutine_desc * last;
     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
    7888        };
    7989
     
    8393
    8494                // list of acceptable functions, null if any
    85                 __small_array_t(struct __acceptable_t) __cfa_anonymous_object;
     95                __cfa_anonymous_object( __small_array_t(struct __acceptable_t) );
    8696        };
    8797
     
    111121        struct __monitor_group_t {
    112122                // currently held monitors
    113                 __small_array_t(monitor_desc*) __cfa_anonymous_object;
     123                __cfa_anonymous_object( __small_array_t(monitor_desc*) );
    114124
    115125                // last function that acquired monitors
     
    122132                struct coroutine_desc  self_cor;
    123133
     134                // current active context
     135                struct coroutine_desc * curr_cor;
     136
    124137                // monitor body used for mutual exclusion
    125138                struct monitor_desc    self_mon;
     
    127140                // pointer to monitor with sufficient lifetime for current monitors
    128141                struct monitor_desc *  self_mon_p;
     142
     143                // pointer to the cluster on which the thread is running
     144                struct cluster * curr_cluster;
    129145
    130146                // monitors currently held by this thread
     
    134150                // instrusive link field for threads
    135151                struct thread_desc * next;
     152
     153                struct {
     154                        struct thread_desc * next;
     155                        struct thread_desc * prev;
     156                } node;
    136157     };
    137158
     
    140161                static inline thread_desc * & get_next( thread_desc & this ) {
    141162                        return this.next;
     163                }
     164
     165                static inline [thread_desc *&, thread_desc *& ] __get( thread_desc & this ) {
     166                        return this.node.[next, prev];
    142167                }
    143168
     
    193218        void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
    194219
    195         #if   defined( __x86_64__ )
     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 )
    196226        #define CtxGet( ctx ) __asm__ ( \
    197227                        "movq %%rsp,%0\n"   \
    198228                        "movq %%rbp,%1\n"   \
    199229                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
    200         #elif defined( __i386__ )
     230        #elif defined( __ARM_ARCH )
    201231        #define CtxGet( ctx ) __asm__ ( \
    202                         "movl %%esp,%0\n"   \
    203                         "movl %%ebp,%1\n"   \
     232                        "mov %0,%%sp\n"   \
     233                        "mov %1,%%r11\n"   \
    204234                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     235        #else
     236                #error unknown hardware architecture
    205237        #endif
    206238
Note: See TracChangeset for help on using the changeset viewer.