Changeset 10a9479d for libcfa/src
- Timestamp:
- Nov 23, 2024, 8:28:37 PM (2 months ago)
- 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. - Location:
- libcfa/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/actor.hfa
rb006c51e r10a9479d 398 398 // TODO: update globals in this file to be static fields once the static fields project is done 399 399 static executor * __actor_executor_ = 0p; 400 static bool __actor_executor_passed = false; // was an executor passed to start_actor_system400 static bool __actor_executor_passed = false; // was an executor passed to actor_start 401 401 static size_t __num_actors_ = 0; // number of actor objects in system 402 402 static struct thread$ * __actor_executor_thd = 0p; // used to wake executor after actors finish … … 410 410 // Once an actor is allocated it must be sent a message or the actor system cannot stop. Hence, its receive 411 411 // 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" ); 413 413 alloc = Nodelete; 414 414 ticket = __get_next_ticket( *__actor_executor_ ); … … 682 682 } 683 683 684 static inline void start_actor_system( size_t num_thds ) {684 static inline void actor_start( size_t num_thds ) { 685 685 __reset_stats(); 686 686 __actor_executor_thd = active_thread(); … … 689 689 } 690 690 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 ) {691 static inline void actor_start() { actor_start( get_proc_count( *active_cluster() ) ); } 692 693 static inline void actor_start( executor & this ) { 694 694 __reset_stats(); 695 695 __actor_executor_thd = active_thread(); … … 698 698 } 699 699 700 static inline void stop_actor_system() {700 static inline void actor_stop() { 701 701 park(); // unparked when actor system is finished 702 702 … … 715 715 struct finished_msg_t { inline message; } finished_msg = __base_msg_finished; 716 716 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; }717 allocation receive( actor & this, delete_msg_t & ) { return Delete; } 718 allocation receive( actor & this, destroy_msg_t & ) { return Destroy; } 719 allocation receive( actor & this, finished_msg_t & ) { return Finished; } 720 720 721 721 // Default messages used all the time. 722 //static struct startmsg_t { inline message; } start_msg; // start actor723 //static struct stopmsg_t { inline message; } stop_msg; // terminate actor722 struct start_msg_t { inline message; } start_msg = __base_msg_finished; // start actor 723 struct stop_msg_t { inline message; } stop_msg = __base_msg_finished; // terminate actor -
libcfa/src/concurrency/barrier.hfa
rb006c51e r10a9479d 1 // 1 // -*- Mode: C -*- 2 // 2 3 // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo 3 // 4 // 4 5 // The contents of this file are covered under the licence agreement in the 5 6 // file "LICENCE" distributed with Cforall. 6 7 // 7 // barrier.hfa -- simple barrier implemented from monitors8 // 9 // Author : Thierry Delisle10 // Created On : Thu Mar 31 16:51:35 202211 // 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 // 15 16 16 17 #pragma once … … 18 19 #include <monitor.hfa> 19 20 20 // Simple barrier based on a monitor 21 // Plan 9 inheritance does not work with monitors. Two monitor locks are created. 22 21 23 monitor 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 31 26 }; 32 27 33 // Constructor 34 void ?{}( barrier & this, unsigned width ) { 35 this.width = width; 36 this.count = width; // Count backwards so initialize at width 28 static inline void ?{}( barrier & b, unsigned int group ) { 29 b.group = b.arrivals = group; // arrivals count backward 37 30 } 38 31 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. 34 static 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 59 45 } -
libcfa/src/concurrency/monitor.cfa
rb006c51e r10a9479d 10 10 // Created On : Thd Feb 23 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Feb 19 17:00:59 202313 // Update Count : 1 212 // Last Modified On : Thu Nov 21 08:31:55 2024 13 // Update Count : 18 14 14 // 15 15 … … 931 931 932 932 static inline [thread$ *, int] search_entry_queue( const __waitfor_mask_t & mask, monitor$ * monitors [], __lock_size_t count ) { 933 934 933 __queue_t(thread$) & entry_queue = monitors[0]->entry_queue; 935 934 935 #if 0 936 936 #if defined( __CFA_WITH_VERIFY__ ) 937 937 thread$ * last = 0p; 938 938 #endif 939 939 // 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) ) { 944 941 thread$ * curr = *thrd_it; 945 942 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 ); 947 945 /* paranoid */ verifyf( curr != last, "search not making progress, from %p to %p", last, curr ); 948 946 … … 951 949 __acceptable_t * end = end (mask); 952 950 __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 959 955 return [remove( entry_queue, thrd_it ), i]; 960 956 } … … 965 961 #endif 966 962 } 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 968 991 return [0, -1]; 969 992 } -
libcfa/src/rational.cfa
rb006c51e r10a9479d 10 10 // Created On : Wed Apr 6 17:54:28 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 2 07:41:25202413 // Update Count : 19912 // Last Modified On : Mon Nov 11 22:37:12 2024 13 // Update Count : 206 14 14 // 15 15 … … 203 203 204 204 forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, T ); } ) { 205 205 ostype & ?|?( ostype & os, rational(T) r ) { 206 206 return os | r.numerator | '/' | r.denominator; 207 207 } // ?|? -
libcfa/src/rational.hfa
rb006c51e r10a9479d 12 12 // Created On : Wed Apr 6 17:56:25 2016 13 13 // Last Modified By : Peter A. Buhr 14 // Last Modified On : Fri Oct 6 07:52:20 202315 // Update Count : 12 214 // Last Modified On : Fri Nov 8 17:02:09 2024 15 // Update Count : 126 16 16 // 17 17 … … 23 23 // implementation 24 24 25 forall( T | arithmetic( T )) {25 forall( T ) { 26 26 struct rational { 27 27 T numerator, denominator; // invariant: denominator > 0 28 28 }; // rational 29 } 29 30 31 forall( T | arithmetic( T ) ) { 30 32 // constructors 31 33
Note: See TracChangeset
for help on using the changeset viewer.