Changeset 168c007 for src/libcfa


Ignore:
Timestamp:
Mar 21, 2017, 12:50:27 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
da6d4566, f5392c1
Parents:
94a8123 (diff), e04b636 (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:/u/cforall/software/cfa/cfa-cc

Location:
src/libcfa/concurrency
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/coroutine

    r94a8123 r168c007  
    3030};
    3131
    32 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X* this) { return &this->c; } void main(X* this)
     32#define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X* this) { return &this->__cor; } void main(X* this)
    3333
    3434//-----------------------------------------------------------------------------
  • src/libcfa/concurrency/invoke.c

    r94a8123 r168c007  
    5656
    5757void CtxInvokeThread(
     58      void (*dtor)(void *),
    5859      void (*main)(void *),
    5960      struct thread_desc *(*get_thread)(void *),
     
    6364
    6465      struct thread_desc* thrd = get_thread( this );
    65       struct coroutine_desc* cor = &thrd->c;
     66      struct coroutine_desc* cor = &thrd->cor;
    6667      cor->state = Active;
    6768
     
    9192        struct FakeStack {
    9293            void *fixedRegisters[3];                    // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant)
    93             uint32_t mxcr;                              // SSE Status and Control bits (control bits are preserved across function calls)
    94             uint16_t fcw;                               // X97 FPU control word (preserved across function calls)
    95             void *rturn;                                // where to go on return from uSwitch
     94            uint32_t mxcr;                        // SSE Status and Control bits (control bits are preserved across function calls)
     95          uint16_t fcw;                         // X97 FPU control word (preserved across function calls)
     96            void *rturn;                          // where to go on return from uSwitch
    9697            void *dummyReturn;                          // fake return compiler would have pushed on call to uInvoke
    9798            void *argument[3];                          // for 16-byte ABI, 16-byte alignment starts here
     
    105106        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = this;     // argument to invoke
    106107        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke;
     108      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
     109      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
    107110
    108111#elif defined( __x86_64__ )
    109112
    110113      struct FakeStack {
    111             void *fixedRegisters[5];                    // fixed registers rbx, r12, r13, r14, r15
    112             uint32_t mxcr;                              // SSE Status and Control bits (control bits are preserved across function calls)
    113             uint16_t fcw;                               // X97 FPU control word (preserved across function calls)
    114             void *rturn;                                // where to go on return from uSwitch
    115             void *dummyReturn;                          // NULL return address to provide proper alignment
     114            void *fixedRegisters[5];            // fixed registers rbx, r12, r13, r14, r15
     115            uint32_t mxcr;                      // SSE Status and Control bits (control bits are preserved across function calls)
     116            uint16_t fcw;                       // X97 FPU control word (preserved across function calls)
     117            void *rturn;                        // where to go on return from uSwitch
     118            void *dummyReturn;                  // NULL return address to provide proper alignment
    116119      };
    117120
  • src/libcfa/concurrency/invoke.h

    r94a8123 r168c007  
    2828      #define unlikely(x)    __builtin_expect(!!(x), 0)
    2929      #define thread_local _Thread_local
    30       #define SCHEDULER_CAPACITY 10
    3130
    3231      struct spinlock {
     
    6059
    6160      struct coStack_t {
    62             unsigned int size;                // size of stack
    63             void *storage;                            // pointer to stack
    64             void *limit;                              // stack grows towards stack limit
    65             void *base;                               // base of stack
    66             void *context;                            // address of cfa_context_t
    67             void *top;                                // address of top of storage
    68             bool userStack;     
     61            unsigned int size;                  // size of stack
     62            void *storage;                      // pointer to stack
     63            void *limit;                        // stack grows towards stack limit
     64            void *base;                         // base of stack
     65            void *context;                      // address of cfa_context_t
     66            void *top;                          // address of top of storage
     67            bool userStack;                     // whether or not the user allocated the stack
    6968      };
    7069
     
    7271
    7372      struct coroutine_desc {
    74             struct coStack_t stack;
    75             const char *name;                         // textual name for coroutine/task, initialized by uC++ generated code
    76             int errno_;                               // copy of global UNIX variable errno
    77             enum coroutine_state state;       // current execution status for coroutine
    78             struct coroutine_desc *starter;           // first coroutine to resume this one
    79             struct coroutine_desc *last;                      // last coroutine to resume this one
     73            struct coStack_t stack;             // stack information of the coroutine
     74            const char *name;                   // textual name for coroutine/task, initialized by uC++ generated code
     75            int errno_;                         // copy of global UNIX variable errno
     76            enum coroutine_state state;         // current execution status for coroutine
     77            struct coroutine_desc *starter;     // first coroutine to resume this one
     78            struct coroutine_desc *last;              // last coroutine to resume this one
    8079      };
    8180
    8281      struct thread_desc {
    83             struct coroutine_desc c;                 // coroutine body used to store context
     82            struct coroutine_desc cor;            // coroutine body used to store context
    8483            struct signal_once terminated;      // indicate if execuation state is not halted
    85             struct thread_desc * next;               // instrusive link field for threads
     84            struct thread_desc * next;          // instrusive link field for threads
    8685      };
    8786
  • src/libcfa/concurrency/kernel.c

    r94a8123 r168c007  
    107107
    108108void ?{}( thread_desc * this, current_stack_info_t * info) {
    109         (&this->c){ info };
     109        (&this->cor){ info };
    110110}
    111111
     
    113113// Processor coroutine
    114114void ?{}(processorCtx_t * this, processor * proc) {
    115         (&this->c){};
     115        (&this->__cor){};
    116116        this->proc = proc;
    117117        proc->runner = this;
     
    119119
    120120void ?{}(processorCtx_t * this, processor * proc, current_stack_info_t * info) {
    121         (&this->c){ info };
     121        (&this->__cor){ info };
    122122        this->proc = proc;
    123123        proc->runner = this;
     
    255255        processorCtx_t proc_cor_storage = { proc, &info };
    256256
    257         LIB_DEBUG_PRINTF("Coroutine : created stack %p\n", proc_cor_storage.c.stack.base);
     257        LIB_DEBUG_PRINTF("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);
    258258
    259259        //Set global state
    260         proc->current_coroutine = &proc->runner->c;
     260        proc->current_coroutine = &proc->runner->__cor;
    261261        proc->current_thread = NULL;
    262262
     
    268268        // back to here. Instead directly call the main since we already are on the
    269269        // appropriate stack.
    270         proc_cor_storage.c.state = Active;
     270        proc_cor_storage.__cor.state = Active;
    271271      main( &proc_cor_storage );
    272       proc_cor_storage.c.state = Halted;
     272      proc_cor_storage.__cor.state = Halted;
    273273
    274274        // Main routine of the core returned, the core is now fully terminated
     
    359359        this_processor = systemProcessor;
    360360        this_processor->current_thread = mainThread;
    361         this_processor->current_coroutine = &mainThread->c;
     361        this_processor->current_coroutine = &mainThread->cor;
    362362
    363363        // SKULLDUGGERY: Force a context switch to the system processor to set the main thread's context to the current UNIX
  • src/libcfa/concurrency/kernel_private.h

    r94a8123 r168c007  
    3535struct processorCtx_t {
    3636        processor * proc;
    37         coroutine_desc c;
     37        coroutine_desc __cor;
    3838};
    3939
  • src/libcfa/concurrency/monitor

    r94a8123 r168c007  
    3434}
    3535
    36 //Basic entering routine
    37 void enter(monitor_desc *);
    38 void leave(monitor_desc *);
    39 
    4036//Array entering routine
    4137void enter(monitor_desc **, int count);
     
    4945static inline int ?<?(monitor_desc* lhs, monitor_desc* rhs) {
    5046        return ((intptr_t)lhs) < ((intptr_t)rhs);
    51 }
    52 
    53 static inline void ?{}( monitor_guard_t * this, monitor_desc ** m ) {
    54         this->m = m;
    55         this->count = 1;
    56         enter( *this->m );
    5747}
    5848
  • src/libcfa/concurrency/monitor.c

    r94a8123 r168c007  
    7474void enter(monitor_desc ** monitors, int count) {
    7575        for(int i = 0; i < count; i++) {
    76                 // printf("%d\n", i);
    7776                enter( monitors[i] );
    7877        }
     
    8180void leave(monitor_desc ** monitors, int count) {
    8281        for(int i = count - 1; i >= 0; i--) {
    83                 // printf("%d\n", i);
    8482                leave( monitors[i] );
    8583        }
  • src/libcfa/concurrency/thread

    r94a8123 r168c007  
    2828// Anything that is resumed is a coroutine.
    2929trait is_thread(dtype T) {
     30      void ^?{}(T* this);
    3031      void main(T* this);
    3132      thread_desc* get_thread(T* this);
    3233};
    3334
    34 #define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->t; } void main(X* this)
     35#define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->__thrd; } void main(X* this)
    3536
    3637forall( dtype T | is_thread(T) )
    3738static inline coroutine_desc* get_coroutine(T* this) {
    38         return &get_thread(this)->c;
     39        return &get_thread(this)->cor;
    3940}
    4041
    4142static inline coroutine_desc* get_coroutine(thread_desc* this) {
    42         return &this->c;
     43        return &this->cor;
    4344}
    4445
     
    6465void ?{}( scoped(T)* this, P params );
    6566
    66 forall( dtype T | sized(T) | is_thread(T) | { void ^?{}(T*); } )
     67forall( dtype T | sized(T) | is_thread(T) )
    6768void ^?{}( scoped(T)* this );
    6869
  • src/libcfa/concurrency/thread.c

    r94a8123 r168c007  
    4242
    4343void ?{}(thread_desc* this) {
    44         (&this->c){};
    45         this->c.name = "Anonymous Coroutine";
     44        (&this->cor){};
     45        this->cor.name = "Anonymous Coroutine";
    4646        (&this->terminated){};
    4747        this->next = NULL;
     
    4949
    5050void ^?{}(thread_desc* this) {
    51         ^(&this->c){};
     51        ^(&this->cor){};
    5252}
    5353
     
    6464}
    6565
    66 forall( dtype T | sized(T) | is_thread(T) | { void ^?{}(T*); } )
     66forall( dtype T | sized(T) | is_thread(T) )
    6767void ^?{}( scoped(T)* this ) {
    6868        stop(&this->handle);
     
    120120extern "C" {
    121121        void __thread_signal_termination( thread_desc * this ) {
    122                 this->c.state = Halted;
     122                this->cor.state = Halted;
    123123                LIB_DEBUG_PRINTF("Thread end : %p\n", this);
    124124                signal( &this->terminated );   
Note: See TracChangeset for help on using the changeset viewer.