Changeset 8fc45b7


Ignore:
Timestamp:
Nov 2, 2017, 4:01:28 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
025278e
Parents:
4cedd9f
Message:

Internal helper functions now use arrays and references instead of pointers

Location:
src/libcfa/concurrency
Files:
6 edited

Legend:

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

    r4cedd9f r8fc45b7  
    5050      extern "Cforall" {
    5151            void ?{}( struct __thread_queue_t & );
    52             void append( struct __thread_queue_t *, struct thread_desc * );
    53             struct thread_desc * pop_head( struct __thread_queue_t * );
    54             struct thread_desc * remove( struct __thread_queue_t *, struct thread_desc ** );
     52            void append( struct __thread_queue_t &, struct thread_desc * );
     53            struct thread_desc * pop_head( struct __thread_queue_t & );
     54            struct thread_desc * remove( struct __thread_queue_t &, struct thread_desc ** );
    5555
    5656            void ?{}( struct __condition_stack_t & );
    57             void push( struct __condition_stack_t *, struct __condition_criterion_t * );
    58             struct __condition_criterion_t * pop( struct __condition_stack_t * );
     57            void push( struct __condition_stack_t &, struct __condition_criterion_t * );
     58            struct __condition_criterion_t * pop( struct __condition_stack_t & );
    5959
    60             void ?{}(spinlock & this);
     60            void  ?{}(spinlock & this);
    6161            void ^?{}(spinlock & this);
    6262      }
  • src/libcfa/concurrency/kernel

    r4cedd9f r8fc45b7  
    9999};
    100100
    101 void ?{}(processor & this);
    102 void ?{}(processor & this, cluster * cltr);
     101void  ?{}(processor & this);
     102void  ?{}(processor & this, cluster * cltr);
    103103void ^?{}(processor & this);
    104104
  • src/libcfa/concurrency/kernel.c

    r4cedd9f r8fc45b7  
    335335
    336336        lock(   &this_processor->cltr->ready_queue_lock DEBUG_CTX2 );
    337         append( &this_processor->cltr->ready_queue, thrd );
     337        append( this_processor->cltr->ready_queue, thrd );
    338338        unlock( &this_processor->cltr->ready_queue_lock );
    339339
     
    344344        verify( disable_preempt_count > 0 );
    345345        lock( &this->ready_queue_lock DEBUG_CTX2 );
    346         thread_desc * head = pop_head( &this->ready_queue );
     346        thread_desc * head = pop_head( this->ready_queue );
    347347        unlock( &this->ready_queue_lock );
    348348        verify( disable_preempt_count > 0 );
     
    398398}
    399399
    400 void BlockInternal(spinlock ** locks, unsigned short count) {
     400void BlockInternal(spinlock * locks [], unsigned short count) {
    401401        disable_interrupts();
    402402        this_processor->finish.action_code = Release_Multi;
     
    411411}
    412412
    413 void BlockInternal(spinlock ** locks, unsigned short lock_count, thread_desc ** thrds, unsigned short thrd_count) {
     413void BlockInternal(spinlock * locks [], unsigned short lock_count, thread_desc * thrds [], unsigned short thrd_count) {
    414414        disable_interrupts();
    415415        this_processor->finish.action_code = Release_Multi_Schedule;
     
    623623        if ( this.count < 0 ) {
    624624                // queue current task
    625                 append( &this.waiting, (thread_desc *)this_thread );
     625                append( this.waiting, (thread_desc *)this_thread );
    626626
    627627                // atomically release spin lock and block
     
    639639        if ( this.count <= 0 ) {
    640640                // remove task at head of waiting list
    641                 thrd = pop_head( &this.waiting );
     641                thrd = pop_head( this.waiting );
    642642        }
    643643
     
    655655}
    656656
    657 void append( __thread_queue_t * this, thread_desc * t ) {
    658         verify(this->tail != NULL);
    659         *this->tail = t;
    660         this->tail = &t->next;
    661 }
    662 
    663 thread_desc * pop_head( __thread_queue_t * this ) {
    664         thread_desc * head = this->head;
     657void append( __thread_queue_t & this, thread_desc * t ) {
     658        verify(this.tail != NULL);
     659        *this.tail = t;
     660        this.tail = &t->next;
     661}
     662
     663thread_desc * pop_head( __thread_queue_t & this ) {
     664        thread_desc * head = this.head;
    665665        if( head ) {
    666                 this->head = head->next;
     666                this.head = head->next;
    667667                if( !head->next ) {
    668                         this->tail = &this->head;
     668                        this.tail = &this.head;
    669669                }
    670670                head->next = NULL;
     
    673673}
    674674
    675 thread_desc * remove( __thread_queue_t * this, thread_desc ** it ) {
     675thread_desc * remove( __thread_queue_t & this, thread_desc ** it ) {
    676676        thread_desc * thrd = *it;
    677677        verify( thrd );
     
    679679        (*it) = thrd->next;
    680680
    681         if( this->tail == &thrd->next ) {
    682                 this->tail = it;
     681        if( this.tail == &thrd->next ) {
     682                this.tail = it;
    683683        }
    684684
    685685        thrd->next = NULL;
    686686
    687         verify( (this->head == NULL) == (&this->head == this->tail) );
    688         verify( *this->tail == NULL );
     687        verify( (this.head == NULL) == (&this.head == this.tail) );
     688        verify( *this.tail == NULL );
    689689        return thrd;
    690690}
     
    694694}
    695695
    696 void push( __condition_stack_t * this, __condition_criterion_t * t ) {
     696void push( __condition_stack_t & this, __condition_criterion_t * t ) {
    697697        verify( !t->next );
    698         t->next = this->top;
    699         this->top = t;
    700 }
    701 
    702 __condition_criterion_t * pop( __condition_stack_t * this ) {
    703         __condition_criterion_t * top = this->top;
     698        t->next = this.top;
     699        this.top = t;
     700}
     701
     702__condition_criterion_t * pop( __condition_stack_t & this ) {
     703        __condition_criterion_t * top = this.top;
    704704        if( top ) {
    705                 this->top = top->next;
     705                this.top = top->next;
    706706                top->next = NULL;
    707707        }
  • src/libcfa/concurrency/kernel_private.h

    r4cedd9f r8fc45b7  
    4848void BlockInternal(thread_desc * thrd);
    4949void BlockInternal(spinlock * lock, thread_desc * thrd);
    50 void BlockInternal(spinlock ** locks, unsigned short count);
    51 void BlockInternal(spinlock ** locks, unsigned short count, thread_desc ** thrds, unsigned short thrd_count);
     50void BlockInternal(spinlock * locks [], unsigned short count);
     51void BlockInternal(spinlock * locks [], unsigned short count, thread_desc * thrds [], unsigned short thrd_count);
    5252void LeaveThread(spinlock * lock, thread_desc * thrd);
    5353
  • src/libcfa/concurrency/monitor

    r4cedd9f r8fc45b7  
    9898
    9999void ?{}( __condition_blocked_queue_t & );
    100 void append( __condition_blocked_queue_t *, __condition_node_t * );
    101 __condition_node_t * pop_head( __condition_blocked_queue_t * );
     100void append( __condition_blocked_queue_t &, __condition_node_t * );
     101__condition_node_t * pop_head( __condition_blocked_queue_t & );
    102102
    103103struct condition {
     
    116116}
    117117
    118 void wait( condition & this, uintptr_t user_info = 0 );
    119 bool signal( condition & this );
    120 bool signal_block( condition & this );
    121 static inline bool is_empty( condition & this ) { return !this.blocked.head; }
    122 uintptr_t front( condition & this );
     118              void wait        ( condition & this, uintptr_t user_info = 0 );
     119              bool signal      ( condition & this );
     120              bool signal_block( condition & this );
     121static inline bool is_empty    ( condition & this ) { return !this.blocked.head; }
     122         uintptr_t front       ( condition & this );
    123123
    124124//-----------------------------------------------------------------------------
  • src/libcfa/concurrency/monitor.c

    r4cedd9f r8fc45b7  
    2626// Forward declarations
    2727static inline void set_owner ( monitor_desc * this, thread_desc * owner );
    28 static inline void set_owner ( monitor_desc ** storage, short count, thread_desc * owner );
    29 static inline void set_mask  ( monitor_desc ** storage, short count, const __waitfor_mask_t & mask );
     28static inline void set_owner ( monitor_desc * storage [], short count, thread_desc * owner );
     29static inline void set_mask  ( monitor_desc * storage [], short count, const __waitfor_mask_t & mask );
    3030static inline void reset_mask( monitor_desc * this );
    3131
     
    3333static inline bool is_accepted( monitor_desc * this, const __monitor_group_t & monitors );
    3434
    35 static inline void lock_all( spinlock ** locks, unsigned short count );
    36 static inline void lock_all( monitor_desc ** source, spinlock ** /*out*/ locks, unsigned short count );
    37 static inline void unlock_all( spinlock ** locks, unsigned short count );
    38 static inline void unlock_all( monitor_desc ** locks, unsigned short count );
    39 
    40 static inline void save   ( monitor_desc ** ctx, short count, spinlock ** locks, unsigned int * /*out*/ recursions, __waitfor_mask_t * /*out*/ masks );
    41 static inline void restore( monitor_desc ** ctx, short count, spinlock ** locks, unsigned int * /*in */ recursions, __waitfor_mask_t * /*in */ masks );
    42 
    43 static inline void init     ( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria );
    44 static inline void init_push( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria );
     35static inline void lock_all  ( spinlock * locks [], unsigned short count );
     36static inline void lock_all  ( monitor_desc * source [], spinlock * /*out*/ locks [], unsigned short count );
     37static inline void unlock_all( spinlock * locks [], unsigned short count );
     38static inline void unlock_all( monitor_desc * locks [], unsigned short count );
     39
     40static inline void save   ( monitor_desc * ctx [], short count, spinlock * locks [], unsigned int /*out*/ recursions [], __waitfor_mask_t /*out*/ masks [] );
     41static inline void restore( monitor_desc * ctx [], short count, spinlock * locks [], unsigned int /*in */ recursions [], __waitfor_mask_t /*in */ masks [] );
     42
     43static inline void init     ( int count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] );
     44static inline void init_push( int count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] );
    4545
    4646static inline thread_desc *        check_condition   ( __condition_criterion_t * );
    4747static inline void                 brand_condition   ( condition & );
    48 static inline [thread_desc *, int] search_entry_queue( const __waitfor_mask_t &, monitor_desc ** monitors, int count );
     48static inline [thread_desc *, int] search_entry_queue( const __waitfor_mask_t &, monitor_desc * monitors [], int count );
    4949
    5050forall(dtype T | sized( T ))
    51 static inline short insert_unique( T ** array, short & size, T * val );
     51static inline short insert_unique( T * array [], short & size, T * val );
    5252static inline short count_max    ( const __waitfor_mask_t & mask );
    53 static inline short aggregate    ( monitor_desc ** storage, const __waitfor_mask_t & mask );
     53static inline short aggregate    ( monitor_desc * storage [], const __waitfor_mask_t & mask );
    5454
    5555//-----------------------------------------------------------------------------
     
    5858        __condition_node_t waiter = { thrd, count, user_info };   /* Create the node specific to this wait operation                                     */ \
    5959        __condition_criterion_t criteria[count];                  /* Create the creteria this wait operation needs to wake up                            */ \
    60         init( count, monitors, &waiter, criteria );               /* Link everything together                                                            */ \
     60        init( count, monitors, waiter, criteria );                /* Link everything together                                                            */ \
    6161
    6262#define wait_ctx_primed(thrd, user_info)                        /* Create the necessary information to use the signaller stack                         */ \
    6363        __condition_node_t waiter = { thrd, count, user_info };   /* Create the node specific to this wait operation                                     */ \
    6464        __condition_criterion_t criteria[count];                  /* Create the creteria this wait operation needs to wake up                            */ \
    65         init_push( count, monitors, &waiter, criteria );          /* Link everything together and push it to the AS-Stack                                */ \
     65        init_push( count, monitors, waiter, criteria );           /* Link everything together and push it to the AS-Stack                                */ \
    6666
    6767#define monitor_ctx( mons, cnt )                                /* Define that create the necessary struct for internal/external scheduling operations */ \
     
    114114
    115115                        // Some one else has the monitor, wait in line for it
    116                         append( &this->entry_queue, thrd );
     116                        append( this->entry_queue, thrd );
    117117                        BlockInternal( &this->lock );
    118118
     
    160160
    161161                        // Wake the thread that is waiting for this
    162                         __condition_criterion_t * urgent = pop( &this->signal_stack );
     162                        __condition_criterion_t * urgent = pop( this->signal_stack );
    163163                        verify( urgent );
    164164
     
    182182
    183183                        // Some one else has the monitor, wait in line for it
    184                         append( &this->entry_queue, thrd );
     184                        append( this->entry_queue, thrd );
    185185                        BlockInternal( &this->lock );
    186186
     
    279279// Leave multiple monitor
    280280// relies on the monitor array being sorted
    281 static inline void leave(monitor_desc ** monitors, int count) {
     281static inline void leave(monitor_desc * monitors [], int count) {
    282282        for(int i = count - 1; i >= 0; i--) {
    283283                __leave_monitor_desc( monitors[i] );
     
    287287// Ctor for monitor guard
    288288// Sorts monitors before entering
    289 void ?{}( monitor_guard_t & this, monitor_desc ** m, int count, fptr_t func ) {
     289void ?{}( monitor_guard_t & this, monitor_desc * m [], int count, fptr_t func ) {
    290290        // Store current array
    291291        this.m = m;
     
    333333// Ctor for monitor guard
    334334// Sorts monitors before entering
    335 void ?{}( monitor_dtor_guard_t & this, monitor_desc ** m, fptr_t func ) {
     335void ?{}( monitor_dtor_guard_t & this, monitor_desc * m [], fptr_t func ) {
    336336        // Store current array
    337337        this.m = *m;
     
    378378}
    379379
    380 void ?{}(__condition_criterion_t & this, monitor_desc * target, __condition_node_t * owner ) {
     380void ?{}(__condition_criterion_t & this, monitor_desc * target, __condition_node_t & owner ) {
    381381        this.ready  = false;
    382382        this.target = target;
    383         this.owner  = owner;
     383        this.owner  = &owner;
    384384        this.next   = NULL;
    385385}
     
    403403        // Append the current wait operation to the ones already queued on the condition
    404404        // We don't need locks for that since conditions must always be waited on inside monitor mutual exclusion
    405         append( &this.blocked, &waiter );
     405        append( this.blocked, &waiter );
    406406
    407407        // Lock all monitors (aggregates the locks as well)
     
    456456
    457457        //Pop the head of the waiting queue
    458         __condition_node_t * node = pop_head( &this.blocked );
     458        __condition_node_t * node = pop_head( this.blocked );
    459459
    460460        //Add the thread to the proper AS stack
     
    462462                __condition_criterion_t * crit = &node->criteria[i];
    463463                assert( !crit->ready );
    464                 push( &crit->target->signal_stack, crit );
     464                push( crit->target->signal_stack, crit );
    465465        }
    466466
     
    491491
    492492        //Find the thread to run
    493         thread_desc * signallee = pop_head( &this.blocked )->waiting_thread;
     493        thread_desc * signallee = pop_head( this.blocked )->waiting_thread;
    494494        set_owner( monitors, count, signallee );
    495495
     
    569569
    570570                                __condition_criterion_t * dtor_crit = mon2dtor->dtor_node->criteria;
    571                                 push( &mon2dtor->signal_stack, dtor_crit );
     571                                push( mon2dtor->signal_stack, dtor_crit );
    572572
    573573                                unlock_all( locks, count );
     
    661661}
    662662
    663 static inline void set_owner( monitor_desc ** monitors, short count, thread_desc * owner ) {
     663static inline void set_owner( monitor_desc * monitors [], short count, thread_desc * owner ) {
    664664        monitors[0]->owner     = owner;
    665665        monitors[0]->recursion = 1;
     
    670670}
    671671
    672 static inline void set_mask( monitor_desc ** storage, short count, const __waitfor_mask_t & mask ) {
     672static inline void set_mask( monitor_desc * storage [], short count, const __waitfor_mask_t & mask ) {
    673673        for(int i = 0; i < count; i++) {
    674674                storage[i]->mask = mask;
     
    685685        //Check the signaller stack
    686686        LIB_DEBUG_PRINT_SAFE("Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
    687         __condition_criterion_t * urgent = pop( &this->signal_stack );
     687        __condition_criterion_t * urgent = pop( this->signal_stack );
    688688        if( urgent ) {
    689689                //The signaller stack is not empty,
     
    697697        // No signaller thread
    698698        // Get the next thread in the entry_queue
    699         thread_desc * new_owner = pop_head( &this->entry_queue );
     699        thread_desc * new_owner = pop_head( this->entry_queue );
    700700        set_owner( this, new_owner );
    701701
     
    725725}
    726726
    727 static inline void init( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria ) {
     727static inline void init( int count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] ) {
    728728        for(int i = 0; i < count; i++) {
    729729                (criteria[i]){ monitors[i], waiter };
    730730        }
    731731
    732         waiter->criteria = criteria;
    733 }
    734 
    735 static inline void init_push( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria ) {
     732        waiter.criteria = criteria;
     733}
     734
     735static inline void init_push( int count, monitor_desc * monitors [], __condition_node_t & waiter, __condition_criterion_t criteria [] ) {
    736736        for(int i = 0; i < count; i++) {
    737737                (criteria[i]){ monitors[i], waiter };
    738738                LIB_DEBUG_PRINT_SAFE( "Kernel :  target %p = %p\n", criteria[i].target, &criteria[i] );
    739                 push( &criteria[i].target->signal_stack, &criteria[i] );
    740         }
    741 
    742         waiter->criteria = criteria;
    743 }
    744 
    745 static inline void lock_all( spinlock ** locks, unsigned short count ) {
     739                push( criteria[i].target->signal_stack, &criteria[i] );
     740        }
     741
     742        waiter.criteria = criteria;
     743}
     744
     745static inline void lock_all( spinlock * locks [], unsigned short count ) {
    746746        for( int i = 0; i < count; i++ ) {
    747747                lock_yield( locks[i] DEBUG_CTX2 );
     
    749749}
    750750
    751 static inline void lock_all( monitor_desc ** source, spinlock ** /*out*/ locks, unsigned short count ) {
     751static inline void lock_all( monitor_desc * source [], spinlock * /*out*/ locks [], unsigned short count ) {
    752752        for( int i = 0; i < count; i++ ) {
    753753                spinlock * l = &source[i]->lock;
     
    757757}
    758758
    759 static inline void unlock_all( spinlock ** locks, unsigned short count ) {
     759static inline void unlock_all( spinlock * locks [], unsigned short count ) {
    760760        for( int i = 0; i < count; i++ ) {
    761761                unlock( locks[i] );
     
    763763}
    764764
    765 static inline void unlock_all( monitor_desc ** locks, unsigned short count ) {
     765static inline void unlock_all( monitor_desc * locks [], unsigned short count ) {
    766766        for( int i = 0; i < count; i++ ) {
    767767                unlock( &locks[i]->lock );
     
    769769}
    770770
    771 static inline void save( monitor_desc ** ctx, short count, __attribute((unused)) spinlock ** locks, unsigned int * /*out*/ recursions, __waitfor_mask_t * /*out*/ masks ) {
     771static inline void save(
     772        monitor_desc * ctx [],
     773        short count,
     774        __attribute((unused)) spinlock * locks [],
     775        unsigned int /*out*/ recursions [],
     776        __waitfor_mask_t /*out*/ masks []
     777) {
    772778        for( int i = 0; i < count; i++ ) {
    773779                recursions[i] = ctx[i]->recursion;
     
    776782}
    777783
    778 static inline void restore( monitor_desc ** ctx, short count, spinlock ** locks, unsigned int * /*out*/ recursions, __waitfor_mask_t * /*out*/ masks ) {
     784static inline void restore(
     785        monitor_desc * ctx [],
     786        short count,
     787        spinlock * locks [],
     788        unsigned int /*out*/ recursions [],
     789        __waitfor_mask_t /*out*/ masks []
     790) {
    779791        lock_all( locks, count );
    780792        for( int i = 0; i < count; i++ ) {
     
    825837}
    826838
    827 static inline [thread_desc *, int] search_entry_queue( const __waitfor_mask_t & mask, monitor_desc ** monitors, int count ) {
    828 
    829         __thread_queue_t * entry_queue = &monitors[0]->entry_queue;
     839static inline [thread_desc *, int] search_entry_queue( const __waitfor_mask_t & mask, monitor_desc * monitors [], int count ) {
     840
     841        __thread_queue_t & entry_queue = monitors[0]->entry_queue;
    830842
    831843        // For each thread in the entry-queue
    832         for(    thread_desc ** thrd_it = &entry_queue->head;
     844        for(    thread_desc ** thrd_it = &entry_queue.head;
    833845                *thrd_it;
    834846                thrd_it = &(*thrd_it)->next
     
    852864
    853865forall(dtype T | sized( T ))
    854 static inline short insert_unique( T ** array, short & size, T * val ) {
     866static inline short insert_unique( T * array [], short & size, T * val ) {
    855867        if( !val ) return size;
    856868
     
    872884}
    873885
    874 static inline short aggregate( monitor_desc ** storage, const __waitfor_mask_t & mask ) {
     886static inline short aggregate( monitor_desc * storage [], const __waitfor_mask_t & mask ) {
    875887        short size = 0;
    876888        for( int i = 0; i < mask.size; i++ ) {
     
    890902}
    891903
    892 void append( __condition_blocked_queue_t * this, __condition_node_t * c ) {
    893         verify(this->tail != NULL);
    894         *this->tail = c;
    895         this->tail = &c->next;
    896 }
    897 
    898 __condition_node_t * pop_head( __condition_blocked_queue_t * this ) {
    899         __condition_node_t * head = this->head;
     904void append( __condition_blocked_queue_t & this, __condition_node_t * c ) {
     905        verify(this.tail != NULL);
     906        *this.tail = c;
     907        this.tail = &c->next;
     908}
     909
     910__condition_node_t * pop_head( __condition_blocked_queue_t & this ) {
     911        __condition_node_t * head = this.head;
    900912        if( head ) {
    901                 this->head = head->next;
     913                this.head = head->next;
    902914                if( !head->next ) {
    903                         this->tail = &this->head;
     915                        this.tail = &this.head;
    904916                }
    905917                head->next = NULL;
Note: See TracChangeset for help on using the changeset viewer.