Ignore:
Timestamp:
Nov 20, 2017, 12:12:34 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:
fdd3786
Parents:
b7f8cb4
Message:

Added generic containers for runtime.
Moved some internal code to bits folder.
consistently used cforall instead of CFORALL define.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/monitor.c

    rb7f8cb4 r0cf5b79  
    280280static inline void enter( __monitor_group_t monitors ) {
    281281        for( __lock_size_t i = 0; i < monitors.size; i++) {
    282                 __enter_monitor_desc( monitors.list[i], monitors );
     282                __enter_monitor_desc( monitors[i], monitors );
    283283        }
    284284}
     
    303303
    304304        // Save previous thread context
    305         this.[prev_mntrs, prev_count, prev_func] = this_thread->monitors.[list, size, func];
     305        this.prev = this_thread->monitors;
    306306
    307307        // Update thread context (needed for conditions)
    308         this_thread->monitors.[list, size, func] = [m, count, func];
     308        (this_thread->monitors){m, count, func};
    309309
    310310        // LIB_DEBUG_PRINT_SAFE("MGUARD : enter %d\n", count);
     
    328328
    329329        // Restore thread context
    330         this_thread->monitors.[list, size, func] = this.[prev_mntrs, prev_count, prev_func];
     330        this_thread->monitors = this.prev;
    331331}
    332332
     
    338338
    339339        // Save previous thread context
    340         this.[prev_mntrs, prev_count, prev_func] = this_thread->monitors.[list, size, func];
     340        this.prev = this_thread->monitors;
    341341
    342342        // Update thread context (needed for conditions)
    343         this_thread->monitors.[list, size, func] = [m, 1, func];
     343        (this_thread->monitors){m, 1, func};
    344344
    345345        __enter_monitor_dtor( this.m, func );
     
    352352
    353353        // Restore thread context
    354         this_thread->monitors.[list, size, func] = this.[prev_mntrs, prev_count, prev_func];
     354        this_thread->monitors = this.prev;
    355355}
    356356
     
    437437
    438438                for(int i = 0; i < this.monitor_count; i++) {
    439                         if ( this.monitors[i] != this_thrd->monitors.list[i] ) {
    440                                 abortf( "Signal on condition %p made with different monitor, expected %p got %i", &this, this.monitors[i], this_thrd->monitors.list[i] );
     439                        if ( this.monitors[i] != this_thrd->monitors[i] ) {
     440                                abortf( "Signal on condition %p made with different monitor, expected %p got %i", &this, this.monitors[i], this_thrd->monitors[i] );
    441441                        }
    442442                }
     
    510510                "Possible cause is not checking if the condition is empty before reading stored data."
    511511        );
    512         return this.blocked.head->user_info;
     512        return ((typeof(this.blocked.head))this.blocked.head)->user_info;
    513513}
    514514
     
    554554                if( next ) {
    555555                        *mask.accepted = index;
    556                         if( mask.clauses[index].is_dtor ) {
     556                        __acceptable_t& accepted = mask[index];
     557                        if( accepted.is_dtor ) {
    557558                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : dtor already there\n");
    558                                 verifyf( mask.clauses[index].size == 1        , "ERROR: Accepted dtor has more than 1 mutex parameter." );
    559 
    560                                 monitor_desc * mon2dtor = mask.clauses[index].list[0];
     559                                verifyf( accepted.size == 1, "ERROR: Accepted dtor has more than 1 mutex parameter." );
     560
     561                                monitor_desc * mon2dtor = accepted[0];
    561562                                verifyf( mon2dtor->dtor_node, "ERROR: Accepted monitor has no dtor_node." );
    562563
     
    596597
    597598                        LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
    598 
    599599                        return;
    600600                }
     
    671671static inline void reset_mask( monitor_desc * this ) {
    672672        this->mask.accepted = NULL;
    673         this->mask.clauses = NULL;
     673        this->mask.data = NULL;
    674674        this->mask.size = 0;
    675675}
     
    697697
    698698static inline bool is_accepted( monitor_desc * this, const __monitor_group_t & group ) {
    699         __acceptable_t * it = this->mask.clauses; // Optim
     699        __acceptable_t * it = this->mask.data; // Optim
    700700        __lock_size_t count = this->mask.size;
    701701
     
    820820        if( !this.monitors ) {
    821821                // LIB_DEBUG_PRINT_SAFE("Branding\n");
    822                 assertf( thrd->monitors.list != NULL, "No current monitor to brand condition %p", thrd->monitors.list );
     822                assertf( thrd->monitors.data != NULL, "No current monitor to brand condition %p", thrd->monitors.data );
    823823                this.monitor_count = thrd->monitors.size;
    824824
    825825                this.monitors = malloc( this.monitor_count * sizeof( *this.monitors ) );
    826826                for( int i = 0; i < this.monitor_count; i++ ) {
    827                         this.monitors[i] = thrd->monitors.list[i];
     827                        this.monitors[i] = thrd->monitors[i];
    828828                }
    829829        }
     
    832832static inline [thread_desc *, int] search_entry_queue( const __waitfor_mask_t & mask, monitor_desc * monitors [], __lock_size_t count ) {
    833833
    834         __thread_queue_t & entry_queue = monitors[0]->entry_queue;
     834        __queue_t(thread_desc) & entry_queue = monitors[0]->entry_queue;
    835835
    836836        // For each thread in the entry-queue
     
    841841                // For each acceptable check if it matches
    842842                int i = 0;
    843                 __acceptable_t * end = mask.clauses + mask.size;
    844                 for( __acceptable_t * it = mask.clauses; it != end; it++, i++ ) {
     843                __acceptable_t * end   = end  (mask);
     844                __acceptable_t * begin = begin(mask);
     845                for( __acceptable_t * it = begin; it != end; it++, i++ ) {
    845846                        // Check if we have a match
    846847                        if( *it == (*thrd_it)->monitors ) {
     
    872873        __lock_size_t max = 0;
    873874        for( __lock_size_t i = 0; i < mask.size; i++ ) {
    874                 max += mask.clauses[i].size;
     875                __acceptable_t & accepted = mask[i];
     876                max += accepted.size;
    875877        }
    876878        return max;
     
    880882        __lock_size_t size = 0;
    881883        for( __lock_size_t i = 0; i < mask.size; i++ ) {
    882                 __libcfa_small_sort( mask.clauses[i].list, mask.clauses[i].size );
    883                 for( __lock_size_t j = 0; j < mask.clauses[i].size; j++) {
    884                         insert_unique( storage, size, mask.clauses[i].list[j] );
     884                __acceptable_t & accepted = mask[i];
     885                __libcfa_small_sort( accepted.data, accepted.size );
     886                for( __lock_size_t j = 0; j < accepted.size; j++) {
     887                        insert_unique( storage, size, accepted[j] );
    885888                }
    886889        }
     
    888891        __libcfa_small_sort( storage, size );
    889892        return size;
    890 }
    891 
    892 void ?{}( __condition_blocked_queue_t & this ) {
    893         this.head = NULL;
    894         this.tail = &this.head;
    895 }
    896 
    897 void append( __condition_blocked_queue_t & this, __condition_node_t * c ) {
    898         verify(this.tail != NULL);
    899         *this.tail = c;
    900         this.tail = &c->next;
    901 }
    902 
    903 __condition_node_t * pop_head( __condition_blocked_queue_t & this ) {
    904         __condition_node_t * head = this.head;
    905         if( head ) {
    906                 this.head = head->next;
    907                 if( !head->next ) {
    908                         this.tail = &this.head;
    909                 }
    910                 head->next = NULL;
    911         }
    912         return head;
    913893}
    914894
Note: See TracChangeset for help on using the changeset viewer.