Ignore:
Timestamp:
Mar 15, 2017, 9:43:15 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
27fed7f1, 738e304
Parents:
bf4ac09 (diff), 9b443c7f (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.
git-author:
Peter A. Buhr <pabuhr@…> (03/15/17 21:25:49)
git-committer:
Peter A. Buhr <pabuhr@…> (03/15/17 21:43:15)
Message:

Merge branch 'master' of plg2:software/cfa/cfa-cc

Location:
src/libcfa/concurrency
Files:
7 edited
4 moved

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/coroutine

    rbf4ac09 rf2e40a9f  
    66// file "LICENCE" distributed with Cforall.
    77//
    8 // coroutines --
     8// coroutine --
    99//
    1010// Author           : Thierry Delisle
     
    2727trait is_coroutine(dtype T) {
    2828      void main(T * this);
    29       coroutine * get_coroutine(T * this);
     29      coroutine_desc * get_coroutine(T * this);
    3030};
    3131
    32 #define DECL_COROUTINE(X) static inline coroutine* 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->c; } void main(X* this)
    3333
    3434//-----------------------------------------------------------------------------
    3535// Ctors and dtors
    3636void ?{}(coStack_t * this);
    37 void ?{}(coroutine * this);
    38 void ?{}(coroutine * this, const char * name);
     37void ?{}(coroutine_desc * this);
     38void ?{}(coroutine_desc * this, const char * name);
    3939void ^?{}(coStack_t * this);
    40 void ^?{}(coroutine * this);
     40void ^?{}(coroutine_desc * this);
    4141
    4242//-----------------------------------------------------------------------------
     
    6363
    6464// Get current coroutine
    65 coroutine * this_coroutine(void);
     65coroutine_desc * this_coroutine(void);
    6666
    6767// Private wrappers for context switch and stack creation
    68 extern void CoroutineCtxSwitch(coroutine * src, coroutine * dst);
     68extern void CoroutineCtxSwitch(coroutine_desc * src, coroutine_desc * dst);
    6969extern void create_stack( coStack_t * this, unsigned int storageSize );
    7070
    7171// Suspend implementation inlined for performance
    7272static inline void suspend() {
    73       coroutine * src = this_coroutine();               // optimization
     73      coroutine_desc * src = this_coroutine();          // optimization
    7474
    7575        assertf( src->last != 0,
     
    8888forall(dtype T | is_coroutine(T))
    8989static inline void resume(T * cor) {
    90         coroutine * src = this_coroutine();             // optimization
    91         coroutine * dst = get_coroutine(cor);
     90        coroutine_desc * src = this_coroutine();                // optimization
     91        coroutine_desc * dst = get_coroutine(cor);
    9292
    9393      if( unlikely(!dst->stack.base) ) {
     
    111111}
    112112
    113 static inline void resume(coroutine * dst) {
    114         coroutine * src = this_coroutine();             // optimization
     113static inline void resume(coroutine_desc * dst) {
     114        coroutine_desc * src = this_coroutine();                // optimization
    115115
    116116      // not resuming self ?
  • src/libcfa/concurrency/coroutine.c

    rbf4ac09 rf2e40a9f  
    66// file "LICENCE" distributed with Cforall.
    77//
    8 // coroutines.c --
     8// coroutine.c --
    99//
    1010// Author           : Thierry Delisle
     
    1515//
    1616
    17 #include "coroutines"
     17#include "coroutine"
    1818
    1919extern "C" {
     
    3232#include "invoke.h"
    3333
    34 extern processor * get_this_processor();
     34extern thread_local processor * this_processor;
    3535
    3636//-----------------------------------------------------------------------------
     
    6060}
    6161
    62 void ?{}(coroutine* this) {
     62void ?{}(coroutine_desc* this) {
    6363        this{ "Anonymous Coroutine" };
    6464}
    6565
    66 void ?{}(coroutine* this, const char * name) {
     66void ?{}(coroutine_desc* this, const char * name) {
    6767        this->name = name;
    6868        this->errno_ = 0;
     
    7272}
    7373
    74 void ?{}(coroutine* this, size_t size) {
     74void ?{}(coroutine_desc* this, size_t size) {
    7575        this{};
    7676        (&this->stack){size};
     
    8888}
    8989
    90 void ^?{}(coroutine* this) {}
     90void ^?{}(coroutine_desc* this) {}
    9191
    9292// Part of the Public API
     
    9494forall(dtype T | is_coroutine(T))
    9595void prime(T* cor) {
    96         coroutine* this = get_coroutine(cor);
     96        coroutine_desc* this = get_coroutine(cor);
    9797        assert(this->state == Start);
    9898
     
    102102
    103103// Wrapper for co
    104 void CoroutineCtxSwitch(coroutine* src, coroutine* dst) {
     104void CoroutineCtxSwitch(coroutine_desc* src, coroutine_desc* dst) {
    105105        // THREAD_GETMEM( This )->disableInterrupts();
    106106
     
    109109
    110110        // set new coroutine that task is executing
    111         get_this_processor()->current_coroutine = dst;                 
     111        this_processor->current_coroutine = dst;
    112112
    113113        // context switch to specified coroutine
  • src/libcfa/concurrency/invoke.c

    rbf4ac09 rf2e40a9f  
    2929
    3030extern void __suspend_internal(void);
    31 extern void __thread_signal_termination(struct thread*);
     31extern void __thread_signal_termination(struct thread_desc*);
    3232
    3333void CtxInvokeCoroutine(
    3434      void (*main)(void *),
    35       struct coroutine *(*get_coroutine)(void *),
     35      struct coroutine_desc *(*get_coroutine)(void *),
    3636      void *this
    3737) {
    3838      // LIB_DEBUG_PRINTF("Invoke Coroutine : Received %p (main %p, get_c %p)\n", this, main, get_coroutine);
    3939
    40       struct coroutine* cor = get_coroutine( this );
     40      struct coroutine_desc* cor = get_coroutine( this );
    4141
    4242      if(cor->state == Primed) {
     
    5757void CtxInvokeThread(
    5858      void (*main)(void *),
    59       struct thread *(*get_thread)(void *),
     59      struct thread_desc *(*get_thread)(void *),
    6060      void *this
    6161) {
    6262      __suspend_internal();
    6363
    64       struct thread* thrd = get_thread( this );
    65       struct coroutine* cor = &thrd->c;
     64      struct thread_desc* thrd = get_thread( this );
     65      struct coroutine_desc* cor = &thrd->c;
    6666      cor->state = Active;
    6767
     
    7979void CtxStart(
    8080      void (*main)(void *),
    81       struct coroutine *(*get_coroutine)(void *),
     81      struct coroutine_desc *(*get_coroutine)(void *),
    8282      void *this,
    8383      void (*invoke)(void *)
  • src/libcfa/concurrency/invoke.h

    rbf4ac09 rf2e40a9f  
    3535
    3636      struct simple_thread_list {
    37             struct thread * head;
    38             struct thread ** tail;
     37            struct thread_desc * head;
     38            struct thread_desc ** tail;
    3939      };
    4040
     
    4848      extern "Cforall" {
    4949            void ?{}( struct simple_thread_list * );
    50             void append( struct simple_thread_list *, struct thread * );
    51             struct thread * pop_head( struct simple_thread_list * );
     50            void append( struct simple_thread_list *, struct thread_desc * );
     51            struct thread_desc * pop_head( struct simple_thread_list * );
    5252
    5353            void ?{}(spinlock * this);
     
    7171      enum coroutine_state { Halted, Start, Inactive, Active, Primed };
    7272
    73       struct coroutine {
     73      struct coroutine_desc {
    7474            struct coStack_t stack;
    7575            const char *name;                         // textual name for coroutine/task, initialized by uC++ generated code
    7676            int errno_;                               // copy of global UNIX variable errno
    7777            enum coroutine_state state;       // current execution status for coroutine
    78             struct coroutine *starter;        // first coroutine to resume this one
    79             struct coroutine *last;                   // last coroutine to resume this one
     78            struct coroutine_desc *starter;           // first coroutine to resume this one
     79            struct coroutine_desc *last;                      // last coroutine to resume this one
    8080      };
    8181
    82       struct thread {
    83             struct coroutine c;                 // coroutine body used to store context
     82      struct thread_desc {
     83            struct coroutine_desc c;                 // coroutine body used to store context
    8484            struct signal_once terminated;      // indicate if execuation state is not halted
    85             struct thread * next;               // instrusive link field for threads
     85            struct thread_desc * next;               // instrusive link field for threads
    8686      };
    8787
  • src/libcfa/concurrency/kernel

    rbf4ac09 rf2e40a9f  
    66// file "LICENCE" distributed with Cforall.
    77//
    8 // threads --
     8// kernel --
    99//
    1010// Author           : Thierry Delisle
     
    4949struct FinishAction {
    5050        FinishOpCode action_code;
    51         thread * thrd;
     51        thread_desc * thrd;
    5252        spinlock * lock;
    5353};
     
    6262        struct processorCtx_t * runner;
    6363        cluster * cltr;
    64         coroutine * current_coroutine;
    65         thread * current_thread;
     64        coroutine_desc * current_coroutine;
     65        thread_desc * current_thread;
    6666        pthread_t kernel_thread;
    6767       
  • src/libcfa/concurrency/kernel.c

    rbf4ac09 rf2e40a9f  
    4343KERNEL_STORAGE(cluster, systemCluster);
    4444KERNEL_STORAGE(processor, systemProcessor);
    45 KERNEL_STORAGE(thread, mainThread);
     45KERNEL_STORAGE(thread_desc, mainThread);
    4646KERNEL_STORAGE(machine_context_t, mainThread_context);
    4747
    4848cluster * systemCluster;
    4949processor * systemProcessor;
    50 thread * mainThread;
     50thread_desc * mainThread;
    5151
    5252//-----------------------------------------------------------------------------
     
    5555thread_local processor * this_processor;
    5656
    57 processor * get_this_processor() {
    58         return this_processor;
    59 }
    60 
    61 coroutine * this_coroutine(void) {
     57coroutine_desc * this_coroutine(void) {
    6258        return this_processor->current_coroutine;
    6359}
    6460
    65 thread * this_thread(void) {
     61thread_desc * this_thread(void) {
    6662        return this_processor->current_thread;
    6763}
     
    10399}
    104100
    105 void ?{}( coroutine * this, current_stack_info_t * info) {
     101void ?{}( coroutine_desc * this, current_stack_info_t * info) {
    106102        (&this->stack){ info };
    107103        this->name = "Main Thread";
     
    110106}
    111107
    112 void ?{}( thread * this, current_stack_info_t * info) {
     108void ?{}( thread_desc * this, current_stack_info_t * info) {
    113109        (&this->c){ info };
    114110}
     
    179175        LIB_DEBUG_PRINTF("Kernel : core %p starting\n", this);
    180176
    181         thread * readyThread = NULL;
     177        thread_desc * readyThread = NULL;
    182178        for( unsigned int spin_count = 0; ! this->is_terminated; spin_count++ )
    183179        {
     
    206202// runThread runs a thread by context switching
    207203// from the processor coroutine to the target thread
    208 void runThread(processor * this, thread * dst) {
    209         coroutine * proc_cor = get_coroutine(this->runner);
    210         coroutine * thrd_cor = get_coroutine(dst);
     204void runThread(processor * this, thread_desc * dst) {
     205        coroutine_desc * proc_cor = get_coroutine(this->runner);
     206        coroutine_desc * thrd_cor = get_coroutine(dst);
    211207       
    212208        //Reset the terminating actions here
     
    297293//-----------------------------------------------------------------------------
    298294// Scheduler routines
    299 void ScheduleThread( thread * thrd ) {
     295void ScheduleThread( thread_desc * thrd ) {
    300296        assertf( thrd->next == NULL, "Expected null got %p", thrd->next );
    301297       
     
    305301}
    306302
    307 thread * nextThread(cluster * this) {
     303thread_desc * nextThread(cluster * this) {
    308304        lock( &this->lock );
    309         thread * head = pop_head( &this->ready_queue );
     305        thread_desc * head = pop_head( &this->ready_queue );
    310306        unlock( &this->lock );
    311307        return head;
     
    317313
    318314void ScheduleInternal( spinlock * lock ) {
    319         get_this_processor()->finish.action_code = Release;
    320         get_this_processor()->finish.lock = lock;
     315        this_processor->finish.action_code = Release;
     316        this_processor->finish.lock = lock;
    321317        suspend();
    322318}
    323319
    324 void ScheduleInternal( thread * thrd ) {
    325         get_this_processor()->finish.action_code = Schedule;
    326         get_this_processor()->finish.thrd = thrd;
     320void ScheduleInternal( thread_desc * thrd ) {
     321        this_processor->finish.action_code = Schedule;
     322        this_processor->finish.thrd = thrd;
    327323        suspend();
    328324}
    329325
    330 void ScheduleInternal( spinlock * lock, thread * thrd ) {
    331         get_this_processor()->finish.action_code = Release_Schedule;
    332         get_this_processor()->finish.lock = lock;
    333         get_this_processor()->finish.thrd = thrd;
     326void ScheduleInternal( spinlock * lock, thread_desc * thrd ) {
     327        this_processor->finish.action_code = Release_Schedule;
     328        this_processor->finish.lock = lock;
     329        this_processor->finish.thrd = thrd;
    334330        suspend();
    335331}
     
    343339        // SKULLDUGGERY: the mainThread steals the process main thread
    344340        // which will then be scheduled by the systemProcessor normally
    345         mainThread = (thread *)&mainThread_storage;
     341        mainThread = (thread_desc *)&mainThread_storage;
    346342        current_stack_info_t info;
    347343        mainThread{ &info };
     
    440436                this->condition = true;
    441437
    442                 thread * it;
     438                thread_desc * it;
    443439                while( it = pop_head( &this->blocked) ) {
    444440                        ScheduleThread( it );
     
    455451}
    456452
    457 void append( simple_thread_list * this, thread * t ) {
     453void append( simple_thread_list * this, thread_desc * t ) {
    458454        assert(this->tail != NULL);
    459455        *this->tail = t;
     
    461457}
    462458
    463 thread * pop_head( simple_thread_list * this ) {
    464         thread * head = this->head;
     459thread_desc * pop_head( simple_thread_list * this ) {
     460        thread_desc * head = this->head;
    465461        if( head ) {
    466462                this->head = head->next;
  • src/libcfa/concurrency/kernel_private.h

    rbf4ac09 rf2e40a9f  
    66// file "LICENCE" distributed with Cforall.
    77//
    8 // threads --
     8// kernel_private.h --
    99//
    1010// Author           : Thierry Delisle
     
    1919
    2020#include "kernel"
    21 #include "threads"
     21#include "thread"
    2222
    2323//-----------------------------------------------------------------------------
    2424// Scheduler
    25 void ScheduleThread( thread * );
    26 thread * nextThread(cluster * this);
     25void ScheduleThread( thread_desc * );
     26thread_desc * nextThread(cluster * this);
    2727
    2828void ScheduleInternal();
    2929void ScheduleInternal(spinlock * lock);
    30 void ScheduleInternal(thread * thrd);
    31 void ScheduleInternal(spinlock * lock, thread * thrd);
     30void ScheduleInternal(thread_desc * thrd);
     31void ScheduleInternal(spinlock * lock, thread_desc * thrd);
    3232
    3333//-----------------------------------------------------------------------------
     
    3535struct processorCtx_t {
    3636        processor * proc;
    37         coroutine c;
     37        coroutine_desc c;
    3838};
    3939
     
    4242void main(processorCtx_t *);
    4343void start(processor * this);
    44 void runThread(processor * this, thread * dst);
     44void runThread(processor * this, thread_desc * dst);
    4545void finishRunning(processor * this);
    4646void spin(processor * this, unsigned int * spin_count);
     
    5353}
    5454
    55 extern void ThreadCtxSwitch(coroutine * src, coroutine * dst);
     55extern void ThreadCtxSwitch(coroutine_desc * src, coroutine_desc * dst);
    5656
    5757#endif //KERNEL_PRIVATE_H
  • src/libcfa/concurrency/monitor

    rbf4ac09 rf2e40a9f  
    2222#include "stdlib"
    2323
    24 struct __monitor_t {
     24struct monitor_desc {
    2525        spinlock lock;
    26         thread * owner;
     26        thread_desc * owner;
    2727        simple_thread_list entry_queue;
    2828        unsigned int recursion;
    2929};
    3030
    31 static inline void ?{}(__monitor_t * this) {
     31static inline void ?{}(monitor_desc * this) {
    3232        this->owner = 0;
    3333        this->recursion = 0;
     
    3535
    3636//Basic entering routine
    37 void enter(__monitor_t *);
    38 void leave(__monitor_t *);
     37void enter(monitor_desc *);
     38void leave(monitor_desc *);
    3939
    4040//Array entering routine
    41 void enter(__monitor_t **, int count);
    42 void leave(__monitor_t **, int count);
     41void enter(monitor_desc **, int count);
     42void leave(monitor_desc **, int count);
    4343
    4444struct monitor_guard_t {
    45         __monitor_t ** m;
     45        monitor_desc ** m;
    4646        int count;
    4747};
    4848
    49 static inline int ?<?(__monitor_t* lhs, __monitor_t* rhs) {
     49static inline int ?<?(monitor_desc* lhs, monitor_desc* rhs) {
    5050        return ((intptr_t)lhs) < ((intptr_t)rhs);
    5151}
    5252
    53 static inline void ?{}( monitor_guard_t * this, __monitor_t ** m ) {
     53static inline void ?{}( monitor_guard_t * this, monitor_desc ** m ) {
    5454        this->m = m;
    5555        this->count = 1;
     
    5757}
    5858
    59 static inline void ?{}( monitor_guard_t * this, __monitor_t ** m, int count ) {
     59static inline void ?{}( monitor_guard_t * this, monitor_desc ** m, int count ) {
    6060        this->m = m;
    6161        this->count = count;
  • src/libcfa/concurrency/monitor.c

    rbf4ac09 rf2e40a9f  
    66// file "LICENCE" distributed with Cforall.
    77//
    8 // __monitor_t.c --
     8// monitor_desc.c --
    99//
    1010// Author           : Thierry Delisle
     
    1919#include "kernel_private.h"
    2020
    21 void enter(__monitor_t * this) {
     21void enter(monitor_desc * this) {
    2222        lock( &this->lock );
    23         thread * thrd = this_thread();
     23        thread_desc * thrd = this_thread();
    2424
    2525        if( !this->owner ) {
     
    4545}
    4646
    47 void leave(__monitor_t * this) {
     47void leave(monitor_desc * this) {
    4848        lock( &this->lock );
    4949
    50         thread * thrd = this_thread();
     50        thread_desc * thrd = this_thread();
    5151        assert( thrd == this->owner );
    5252
     
    5555
    5656        //If we left the last level of recursion it means we are changing who owns the monitor
    57         thread * new_owner = 0;
     57        thread_desc * new_owner = 0;
    5858        if( this->recursion == 0) {
    5959                //Get the next thread in the list
     
    7272}
    7373
    74 void enter(__monitor_t ** monitors, int count) {
     74void enter(monitor_desc ** monitors, int count) {
    7575        for(int i = 0; i < count; i++) {
    7676                // printf("%d\n", i);
     
    7979}
    8080
    81 void leave(__monitor_t ** monitors, int count) {
     81void leave(monitor_desc ** monitors, int count) {
    8282        for(int i = count - 1; i >= 0; i--) {
    8383                // printf("%d\n", i);
  • src/libcfa/concurrency/thread

    rbf4ac09 rf2e40a9f  
    66// file "LICENCE" distributed with Cforall.
    77//
    8 // threads --
     8// thread --
    99//
    1010// Author           : Thierry Delisle
     
    2121#include "invoke.h"
    2222
    23 #include "coroutines"
     23#include "coroutine"
    2424
    2525//-----------------------------------------------------------------------------
     
    2929trait is_thread(dtype T) {
    3030      void main(T* this);
    31       thread* get_thread(T* this);
     31      thread_desc* get_thread(T* this);
    3232};
    3333
    34 #define DECL_THREAD(X) thread* get_thread(X* this) { return &this->t; } void main(X* this)
     34#define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->t; } void main(X* this)
    3535
    3636forall( dtype T | is_thread(T) )
    37 static inline coroutine* get_coroutine(T* this) {
     37static inline coroutine_desc* get_coroutine(T* this) {
    3838        return &get_thread(this)->c;
    3939}
    4040
    41 static inline coroutine* get_coroutine(thread* this) {
     41static inline coroutine_desc* get_coroutine(thread_desc* this) {
    4242        return &this->c;
    4343}
    4444
    45 thread * this_thread(void);
     45thread_desc * this_thread(void);
    4646
    4747//-----------------------------------------------------------------------------
    4848// Ctors and dtors
    49 void ?{}(thread* this);
    50 void ^?{}(thread* this);
     49void ?{}(thread_desc* this);
     50void ^?{}(thread_desc* this);
    5151
    5252//-----------------------------------------------------------------------------
  • src/libcfa/concurrency/thread.c

    rbf4ac09 rf2e40a9f  
    66// file "LICENCE" distributed with Cforall.
    77//
    8 // threads.c --
     8// thread.c --
    99//
    1010// Author           : Thierry Delisle
     
    1515//
    1616
    17 #include "threads"
     17#include "thread"
    1818
    1919#include "kernel_private.h"
     
    2828}
    2929
    30 extern processor * get_this_processor();
     30extern thread_local processor * this_processor;
    3131
    3232//-----------------------------------------------------------------------------
     
    4141// Thread ctors and dtors
    4242
    43 void ?{}(thread* this) {
     43void ?{}(thread_desc* this) {
    4444        (&this->c){};
    4545        this->c.name = "Anonymous Coroutine";
     
    4848}
    4949
    50 void ^?{}(thread* this) {
     50void ^?{}(thread_desc* this) {
    5151        ^(&this->c){};
    5252}
     
    7474forall( dtype T | is_thread(T) )
    7575void start( T* this ) {
    76         coroutine* thrd_c = get_coroutine(this);
    77         thread*  thrd_h = get_thread   (this);
     76        coroutine_desc* thrd_c = get_coroutine(this);
     77        thread_desc*  thrd_h = get_thread   (this);
    7878        thrd_c->last = this_coroutine();
    79         get_this_processor()->current_coroutine = thrd_c;
     79        this_processor->current_coroutine = thrd_c;
    8080
    8181        LIB_DEBUG_PRINTF("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h);
     
    9494
    9595void yield( void ) {
    96         ScheduleInternal( get_this_processor()->current_thread );
     96        ScheduleInternal( this_processor->current_thread );
    9797}
    9898
    99 void ThreadCtxSwitch(coroutine* src, coroutine* dst) {
     99void ThreadCtxSwitch(coroutine_desc* src, coroutine_desc* dst) {
    100100        // set state of current coroutine to inactive
    101101        src->state = Inactive;
     
    107107        // set new coroutine that the processor is executing
    108108        // and context switch to it
    109         get_this_processor()->current_coroutine = dst; 
     109        this_processor->current_coroutine = dst;
    110110        CtxSwitch( src->stack.context, dst->stack.context );
    111         get_this_processor()->current_coroutine = src; 
     111        this_processor->current_coroutine = src;
    112112
    113113        // set state of new coroutine to active
     
    116116}
    117117
    118 // C Helper to signal the termination of a thread
     118// C Helper to signal the termination of a thread_desc
    119119// Used in invoke.c
    120120extern "C" {
    121         void __thread_signal_termination( thread * this ) {
     121        void __thread_signal_termination( thread_desc * this ) {
    122122                this->c.state = Halted;
    123123                LIB_DEBUG_PRINTF("Thread end : %p\n", this);
Note: See TracChangeset for help on using the changeset viewer.