Changeset 59a0bde
- Timestamp:
- Nov 3, 2017, 5:59:32 PM (7 years ago)
- 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:
- 121ac13
- Parents:
- c1a9c86
- Location:
- src/libcfa/concurrency
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/monitor
rc1a9c86 r59a0bde 41 41 struct monitor_guard_t { 42 42 monitor_desc ** m; 43 intcount;43 __lock_size_t count; 44 44 monitor_desc ** prev_mntrs; 45 45 __lock_size_t prev_count; … … 47 47 }; 48 48 49 void ?{}( monitor_guard_t & this, monitor_desc ** m, int count, void (*func)() );49 void ?{}( monitor_guard_t & this, monitor_desc ** m, __lock_size_t count, void (*func)() ); 50 50 void ^?{}( monitor_guard_t & this ); 51 51 … … 105 105 }; 106 106 107 void ?{}(__condition_node_t & this, thread_desc * waiting_thread, unsigned short count, uintptr_t user_info );107 void ?{}(__condition_node_t & this, thread_desc * waiting_thread, __lock_size_t count, uintptr_t user_info ); 108 108 void ?{}(__condition_criterion_t & this ); 109 109 void ?{}(__condition_criterion_t & this, monitor_desc * target, __condition_node_t * owner ); -
src/libcfa/concurrency/monitor.c
rc1a9c86 r59a0bde 46 46 static inline thread_desc * check_condition ( __condition_criterion_t * ); 47 47 static inline void brand_condition ( condition & ); 48 static inline [thread_desc *, int] search_entry_queue( const __waitfor_mask_t &, monitor_desc * monitors [], int count );48 static inline [thread_desc *, int] search_entry_queue( const __waitfor_mask_t &, monitor_desc * monitors [], __lock_size_t count ); 49 49 50 50 forall(dtype T | sized( T )) 51 static inline short insert_unique( T * array [], short & size, T * val );52 static inline short count_max ( const __waitfor_mask_t & mask );53 static inline short aggregate ( monitor_desc * storage [], const __waitfor_mask_t & mask );51 static inline __lock_size_t insert_unique( T * array [], __lock_size_t & size, T * val ); 52 static inline __lock_size_t count_max ( const __waitfor_mask_t & mask ); 53 static inline __lock_size_t aggregate ( monitor_desc * storage [], const __waitfor_mask_t & mask ); 54 54 55 55 //----------------------------------------------------------------------------- … … 67 67 #define monitor_ctx( mons, cnt ) /* Define that create the necessary struct for internal/external scheduling operations */ \ 68 68 monitor_desc ** monitors = mons; /* Save the targeted monitors */ \ 69 unsigned short count = cnt;/* Save the count to a local variable */ \69 __lock_size_t count = cnt; /* Save the count to a local variable */ \ 70 70 unsigned int recursions[ count ]; /* Save the current recursion levels to restore them later */ \ 71 71 __waitfor_mask_t masks [ count ]; /* Save the current waitfor masks to restore them later */ \ … … 153 153 } 154 154 155 int count = 1;155 __lock_size_t count = 1; 156 156 monitor_desc ** monitors = &this; 157 157 __monitor_group_t group = { &this, 1, func }; … … 272 272 // relies on the monitor array being sorted 273 273 static inline void enter( __monitor_group_t monitors ) { 274 for( int i = 0; i < monitors.size; i++) {274 for( __lock_size_t i = 0; i < monitors.size; i++) { 275 275 __enter_monitor_desc( monitors.list[i], monitors ); 276 276 } … … 279 279 // Leave multiple monitor 280 280 // relies on the monitor array being sorted 281 static inline void leave(monitor_desc * monitors [], int count) {282 for( int i = count - 1; i >= 0; i--) {281 static inline void leave(monitor_desc * monitors [], __lock_size_t count) { 282 for( __lock_size_t i = count - 1; i >= 0; i--) { 283 283 __leave_monitor_desc( monitors[i] ); 284 284 } … … 287 287 // Ctor for monitor guard 288 288 // Sorts monitors before entering 289 void ?{}( monitor_guard_t & this, monitor_desc * m [], int count, fptr_t func ) {289 void ?{}( monitor_guard_t & this, monitor_desc * m [], __lock_size_t count, fptr_t func ) { 290 290 // Store current array 291 291 this.m = m; … … 350 350 //----------------------------------------------------------------------------- 351 351 // Internal scheduling types 352 void ?{}(__condition_node_t & this, thread_desc * waiting_thread, unsigned short count, uintptr_t user_info ) {352 void ?{}(__condition_node_t & this, thread_desc * waiting_thread, __lock_size_t count, uintptr_t user_info ) { 353 353 this.waiting_thread = waiting_thread; 354 354 this.count = count; … … 395 395 396 396 // Find the next thread(s) to run 397 short thread_count = 0;397 __lock_size_t thread_count = 0; 398 398 thread_desc * threads[ count ]; 399 399 __builtin_memset( threads, 0, sizeof( threads ) ); … … 403 403 404 404 // Remove any duplicate threads 405 for( int i = 0; i < count; i++) {405 for( __lock_size_t i = 0; i < count; i++) { 406 406 thread_desc * new_owner = next_thread( monitors[i] ); 407 407 insert_unique( threads, thread_count, new_owner ); … … 436 436 ); 437 437 438 unsigned short count = this.monitor_count;438 __lock_size_t count = this.monitor_count; 439 439 440 440 // Lock all monitors … … 523 523 // This statment doesn't have a contiguous list of monitors... 524 524 // Create one! 525 short max = count_max( mask );525 __lock_size_t max = count_max( mask ); 526 526 monitor_desc * mon_storage[max]; 527 527 __builtin_memset( mon_storage, 0, sizeof( mon_storage ) ); 528 short actual_count = aggregate( mon_storage, mask );529 530 LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, ( short)max);528 __lock_size_t actual_count = aggregate( mon_storage, mask ); 529 530 LIB_DEBUG_PRINT_BUFFER_DECL( "Kernel : waitfor %d (s: %d, m: %d)\n", actual_count, mask.size, (__lock_size_t)max); 531 531 532 532 if(actual_count == 0) return; … … 615 615 set_mask( monitors, count, mask ); 616 616 617 for( int i = 0; i < count; i++) {617 for( __lock_size_t i = 0; i < count; i++) { 618 618 verify( monitors[i]->owner == this_thread ); 619 619 } … … 691 691 static inline bool is_accepted( monitor_desc * this, const __monitor_group_t & group ) { 692 692 __acceptable_t * it = this->mask.clauses; // Optim 693 int count = this->mask.size;693 __lock_size_t count = this->mask.size; 694 694 695 695 // Check if there are any acceptable functions … … 700 700 701 701 // For all acceptable functions check if this is the current function. 702 for( short i = 0; i < count; i++, it++ ) {702 for( __lock_size_t i = 0; i < count; i++, it++ ) { 703 703 if( *it == group ) { 704 704 *this->mask.accepted = i; … … 823 823 } 824 824 825 static inline [thread_desc *, int] search_entry_queue( const __waitfor_mask_t & mask, monitor_desc * monitors [], int count ) {825 static inline [thread_desc *, int] search_entry_queue( const __waitfor_mask_t & mask, monitor_desc * monitors [], __lock_size_t count ) { 826 826 827 827 __thread_queue_t & entry_queue = monitors[0]->entry_queue; … … 850 850 851 851 forall(dtype T | sized( T )) 852 static inline short insert_unique( T * array [], short & size, T * val ) {852 static inline __lock_size_t insert_unique( T * array [], __lock_size_t & size, T * val ) { 853 853 if( !val ) return size; 854 854 855 for( int i = 0; i <= size; i++) {855 for( __lock_size_t i = 0; i <= size; i++) { 856 856 if( array[i] == val ) return size; 857 857 } … … 862 862 } 863 863 864 static inline short count_max( const __waitfor_mask_t & mask ) {865 short max = 0;866 for( int i = 0; i < mask.size; i++ ) {864 static inline __lock_size_t count_max( const __waitfor_mask_t & mask ) { 865 __lock_size_t max = 0; 866 for( __lock_size_t i = 0; i < mask.size; i++ ) { 867 867 max += mask.clauses[i].size; 868 868 } … … 870 870 } 871 871 872 static inline short aggregate( monitor_desc * storage [], const __waitfor_mask_t & mask ) {873 short size = 0;874 for( int i = 0; i < mask.size; i++ ) {872 static inline __lock_size_t aggregate( monitor_desc * storage [], const __waitfor_mask_t & mask ) { 873 __lock_size_t size = 0; 874 for( __lock_size_t i = 0; i < mask.size; i++ ) { 875 875 __libcfa_small_sort( mask.clauses[i].list, mask.clauses[i].size ); 876 for( int j = 0; j < mask.clauses[i].size; j++) {876 for( __lock_size_t j = 0; j < mask.clauses[i].size; j++) { 877 877 insert_unique( storage, size, mask.clauses[i].list[j] ); 878 878 }
Note: See TracChangeset
for help on using the changeset viewer.