Ignore:
Timestamp:
Nov 21, 2024, 8:35:12 AM (4 weeks ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
de7b7a5
Parents:
d945be9
Message:

test patch for respecting lexical priority in waitfor statement

File:
1 edited

Legend:

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

    rd945be9 r1cd2839  
    1010// Created On       : Thd Feb 23 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Feb 19 17:00:59 2023
    13 // Update Count     : 12
     12// Last Modified On : Thu Nov 21 08:31:55 2024
     13// Update Count     : 18
    1414//
    1515
     
    931931
    932932static inline [thread$ *, int] search_entry_queue( const __waitfor_mask_t & mask, monitor$ * monitors [], __lock_size_t count ) {
    933 
    934933        __queue_t(thread$) & entry_queue = monitors[0]->entry_queue;
    935934
     935#if 0
    936936        #if defined( __CFA_WITH_VERIFY__ )
    937937                thread$ * last = 0p;
    938938        #endif
    939939        // For each thread in the entry-queue
    940         for(    thread$ ** thrd_it = &entry_queue.head;
    941                 (*thrd_it) != 1p;
    942                 thrd_it = &get_next(**thrd_it)
    943         ) {
     940        for ( thread$ ** thrd_it = &entry_queue.head; (*thrd_it) != 1p; thrd_it = &get_next(**thrd_it) ) {
    944941                thread$ * curr = *thrd_it;
    945942
    946                 /* paranoid */ verifyf( !last || last->user_link.next == curr, "search not making progress, from %p (%p) to %p", last, last->user_link.next, curr );
     943                /* paranoid */ verifyf( !last || last->user_link.next == curr, "search not making progress, from %p (%p) to %p",
     944                                                                last, last->user_link.next, curr );
    947945                /* paranoid */ verifyf( curr != last, "search not making progress, from %p to %p", last, curr );
    948946
     
    951949                __acceptable_t * end   = end  (mask);
    952950                __acceptable_t * begin = begin(mask);
    953                 for( __acceptable_t * it = begin; it != end; it++, i++ ) {
    954                         // Check if we have a match
    955                         if( *it == curr->monitors ) {
    956 
    957                                 // If we have a match return it
    958                                 // after removeing it from the entry queue
     951                for ( __acceptable_t * it = begin; it != end; it++, i++ ) {
     952                        // Check for match
     953                        if ( *it == curr->monitors ) {
     954                                // If match, return it after removeing it from the entry queue
    959955                                return [remove( entry_queue, thrd_it ), i];
    960956                        }
     
    965961                #endif
    966962        }
    967 
     963#endif
     964        int i = 0;
     965        __acceptable_t * end   = end  (mask);
     966        __acceptable_t * begin = begin(mask);
     967        // For each acceptable (respect lexical priority in waitfor statement)
     968        for ( __acceptable_t * it = begin; it != end; it++, i++ ) {
     969                #if defined( __CFA_WITH_VERIFY__ )
     970                thread$ * last = 0p;
     971                #endif // __CFA_WITH_VERIFY__
     972
     973                for ( thread$ ** thrd_it = &entry_queue.head; (*thrd_it) != 1p; thrd_it = &get_next(**thrd_it) ) {
     974                        thread$ * curr = *thrd_it;
     975
     976                        /* paranoid */ verifyf( !last || last->user_link.next == curr, "search not making progress, from %p (%p) to %p",
     977                                                                        last, last->user_link.next, curr );
     978                        /* paranoid */ verifyf( curr != last, "search not making progress, from %p to %p", last, curr );
     979
     980                        // For each thread in the entry-queue check for a match
     981                        if ( *it == curr->monitors ) {
     982                                // If match, return it after removeing from the entry queue
     983                                return [remove( entry_queue, thrd_it ), i];
     984                        } // if
     985
     986                        #if defined( __CFA_WITH_VERIFY__ )
     987                        last = curr;
     988                        #endif
     989                } // for
     990        } // for
    968991        return [0, -1];
    969992}
Note: See TracChangeset for help on using the changeset viewer.