Changeset 10a9479d for libcfa/src


Ignore:
Timestamp:
Nov 23, 2024, 8:28:37 PM (2 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
956b389
Parents:
b006c51e (diff), de7b7a5 (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:software/cfa/cfa-cc

Location:
libcfa/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/actor.hfa

    rb006c51e r10a9479d  
    398398// TODO: update globals in this file to be static fields once the static fields project is done
    399399static executor * __actor_executor_ = 0p;
    400 static bool __actor_executor_passed = false;                    // was an executor passed to start_actor_system
     400static bool __actor_executor_passed = false;                    // was an executor passed to actor_start
    401401static size_t __num_actors_ = 0;                                                // number of actor objects in system
    402402static struct thread$ * __actor_executor_thd = 0p;              // used to wake executor after actors finish
     
    410410        // Once an actor is allocated it must be sent a message or the actor system cannot stop. Hence, its receive
    411411        // member must be called to end it
    412         DEBUG_ABORT( __actor_executor_ == 0p, "Creating actor before calling start_actor_system() can cause undefined behaviour.\n" );
     412        DEBUG_ABORT( __actor_executor_ == 0p, "Creating actor before calling actor_start() can cause undefined behaviour.\n" );
    413413        alloc = Nodelete;
    414414        ticket = __get_next_ticket( *__actor_executor_ );
     
    682682}
    683683
    684 static inline void start_actor_system( size_t num_thds ) {
     684static inline void actor_start( size_t num_thds ) {
    685685        __reset_stats();
    686686        __actor_executor_thd = active_thread();
     
    689689}
    690690
    691 static inline void start_actor_system() { start_actor_system( get_proc_count( *active_cluster() ) ); }
    692 
    693 static inline void start_actor_system( executor & this ) {
     691static inline void actor_start() { actor_start( get_proc_count( *active_cluster() ) ); }
     692
     693static inline void actor_start( executor & this ) {
    694694        __reset_stats();
    695695        __actor_executor_thd = active_thread();
     
    698698}
    699699
    700 static inline void stop_actor_system() {
     700static inline void actor_stop() {
    701701        park();                                                                                         // unparked when actor system is finished
    702702
     
    715715struct finished_msg_t { inline message; } finished_msg = __base_msg_finished;
    716716
    717 allocation receive( actor & this, delete_msg_t & msg ) { return Delete; }
    718 allocation receive( actor & this, destroy_msg_t & msg ) { return Destroy; }
    719 allocation receive( actor & this, finished_msg_t & msg ) { return Finished; }
     717allocation receive( actor & this, delete_msg_t & ) { return Delete; }
     718allocation receive( actor & this, destroy_msg_t & ) { return Destroy; }
     719allocation receive( actor & this, finished_msg_t & ) { return Finished; }
    720720
    721721// Default messages used all the time.
    722 //static struct startmsg_t { inline message; } start_msg; // start actor
    723 //static struct stopmsg_t { inline message; } stop_msg; // terminate actor
     722struct start_msg_t { inline message; } start_msg = __base_msg_finished; // start actor
     723struct stop_msg_t { inline message; } stop_msg = __base_msg_finished; // terminate actor
  • libcfa/src/concurrency/barrier.hfa

    rb006c51e r10a9479d  
    1 //
     1//                               -*- Mode: C -*-
     2//
    23// Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo
    3 //
     4// 
    45// The contents of this file are covered under the licence agreement in the
    56// file "LICENCE" distributed with Cforall.
    67//
    7 // barrier.hfa -- simple barrier implemented from monitors
    8 //
    9 // Author           : Thierry Delisle
    10 // Created On       : Thu Mar 31 16:51:35 2022
    11 // Last Modified By :
    12 // Last Modified On :
    13 // Update Count     :
    14 //
     8// barrier.hfa -- simple barrier implemented using a monitor
     9// 
     10// Author           : Peter A. Buhr
     11// Created On       : Sun Nov 10 08:07:35 2024
     12// Last Modified By : Peter A. Buhr
     13// Last Modified On : Wed Nov 13 12:37:04 2024
     14// Update Count     : 9
     15// 
    1516
    1617#pragma once
     
    1819#include <monitor.hfa>
    1920
    20 // Simple barrier based on a monitor
     21// Plan 9 inheritance does not work with monitors. Two monitor locks are created.
     22
    2123monitor barrier {
    22         // Number of threads blocking needed to unblock the barrier
    23         // Unsigned should be enough, I don't expect use cases with 2^32 thread barriers.
    24         unsigned width;
    25 
    26         // Current count (counting backwards)
    27         unsigned count;
    28 
    29         // Barrier uses internal scheduling
    30         condition c;
     24        unsigned int group, arrivals;                                           // group size, arrival counter
     25        condition c;                                                                            // wait for group to form
    3126};
    3227
    33 // Constructor
    34 void ?{}( barrier & this, unsigned width ) {
    35         this.width = width;
    36         this.count = width; // Count backwards so initialize at width
     28static inline void ?{}( barrier & b, unsigned int group ) {
     29        b.group = b.arrivals = group;                                           // arrivals count backward
    3730}
    3831
    39 // block until the number of threads needed have blocked
    40 // returns an value indicating the reverse order the threads arrived in
    41 // i.e. last thread will return 0 (and not block)
    42 //      second last thread returns 1
    43 //      etc.
    44 // last is an optional hook that will be called by the last thread
    45 // before unblocking the others
    46 static inline unsigned block(barrier & mutex this, fptr_t last = (fptr_t)0 ) {
    47         this.count -= 1; // prefix decrement so we the last is 0 and not 1
    48         unsigned arrival = this.count; // Note arrival order
    49         if(arrival == 0) {
    50                 if(last) last();
    51                 // If arrived last unblock everyone and reset
    52                 signal_all(this.c);
    53                 this.count = this.width;
    54         } else {
    55                 // Otherwise block
    56                 wait(this.c);
    57         }
    58         return arrival; // return arrival order
     32// Returns a value indicating the reverse order the threads arrived, i.e. last thread returns 0 (and does not block)
     33// last is an optional hook that is called by the Gth thread before unblocking the other threads.
     34static inline unsigned int block( barrier & mutex b, fptr_t last = (fptr_t)0 ) with( b ) {
     35        arrivals -= 1;                                                                          // prefix decrement so last is 0 not 1
     36        unsigned arrived = b.arrivals;                                          // note arrival order
     37        if ( arrivals != 0 ) {                                                          // wait for group to form
     38                wait( b.c );
     39        } else {                                                                                        // group formed
     40                if ( last ) last();                                                             // safe to call
     41                signal_all( c );                                                                // unblock group
     42                arrivals = group;                                                               // reset
     43        } // if
     44        return arrived;                                                                         // return arrival order
    5945}
  • libcfa/src/concurrency/monitor.cfa

    rb006c51e r10a9479d  
    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}
  • libcfa/src/rational.cfa

    rb006c51e r10a9479d  
    1010// Created On       : Wed Apr  6 17:54:28 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Aug  2 07:41:25 2024
    13 // Update Count     : 199
     12// Last Modified On : Mon Nov 11 22:37:12 2024
     13// Update Count     : 206
    1414//
    1515
     
    203203
    204204        forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, T ); } ) {
    205                 ostype & ?|?( ostype & os, rational(T) r ) {
     205        ostype & ?|?( ostype & os, rational(T) r ) {
    206206                        return os | r.numerator | '/' | r.denominator;
    207207                } // ?|?
  • libcfa/src/rational.hfa

    rb006c51e r10a9479d  
    1212// Created On       : Wed Apr  6 17:56:25 2016
    1313// Last Modified By : Peter A. Buhr
    14 // Last Modified On : Fri Oct  6 07:52:20 2023
    15 // Update Count     : 122
     14// Last Modified On : Fri Nov  8 17:02:09 2024
     15// Update Count     : 126
    1616//
    1717
     
    2323// implementation
    2424
    25 forall( T | arithmetic( T ) ) {
     25forall( T ) {
    2626        struct rational {
    2727                T numerator, denominator;                                               // invariant: denominator > 0
    2828        }; // rational
     29}
    2930
     31forall( T | arithmetic( T ) ) {
    3032        // constructors
    3133
Note: See TracChangeset for help on using the changeset viewer.