- Timestamp:
- Sep 9, 2021, 3:56:32 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- d0b9247
- Parents:
- dd1cc02 (diff), d8d512e (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
- Files:
-
- 7 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/prelude/builtins.c
rdd1cc02 r5a40e4e 10 10 // Created On : Fri Jul 21 16:21:03 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 21 13:31:34 202113 // Update Count : 1 2912 // Last Modified On : Sat Aug 14 08:45:54 2021 13 // Update Count : 133 14 14 // 15 15 … … 107 107 #endif // __SIZEOF_INT128__ 108 108 109 // for-control index constraints 110 // forall( T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); T ?+=?( T &, T ); T ?-=?( T &, T ); int ?<?( T, T ); } ) 111 // static inline T __for_control_index_constraints__( T t ) { return t; } 112 109 113 // exponentiation operator implementation 110 114 -
libcfa/src/Makefile.am
rdd1cc02 r5a40e4e 48 48 math.hfa \ 49 49 time_t.hfa \ 50 bits/algorithm.hfa \ 50 51 bits/align.hfa \ 51 52 bits/containers.hfa \ … … 77 78 memory.hfa \ 78 79 parseargs.hfa \ 80 parseconfig.hfa \ 79 81 rational.hfa \ 80 82 stdlib.hfa \ … … 85 87 containers/pair.hfa \ 86 88 containers/result.hfa \ 89 containers/string.hfa \ 90 containers/string_res.hfa \ 87 91 containers/vector.hfa \ 88 92 device/cpu.hfa … … 90 94 libsrc = ${inst_headers_src} ${inst_headers_src:.hfa=.cfa} \ 91 95 assert.cfa \ 92 bits/algorithm.hfa \93 96 bits/debug.cfa \ 94 97 exception.c \ … … 106 109 concurrency/invoke.h \ 107 110 concurrency/future.hfa \ 108 concurrency/kernel/fwd.hfa 111 concurrency/kernel/fwd.hfa \ 112 concurrency/mutex_stmt.hfa 109 113 110 114 inst_thread_headers_src = \ -
libcfa/src/concurrency/kernel/startup.cfa
rdd1cc02 r5a40e4e 235 235 236 236 register_tls( mainProcessor ); 237 mainThread->last_cpu = __kernel_getcpu(); 237 238 238 239 //initialize the global state variables … … 478 479 state = Start; 479 480 self_cor{ info }; 480 last_cpu = __kernel_getcpu();481 481 curr_cor = &self_cor; 482 482 curr_cluster = mainCluster; -
libcfa/src/concurrency/locks.hfa
rdd1cc02 r5a40e4e 324 324 } 325 325 326 // linear backoff bounded by spin_count327 spin = spin_start;328 int spin_counter = 0;329 int yield_counter = 0;330 for ( ;; ) {331 if(try_lock_contention(this)) return true;332 if(spin_counter < spin_count) {333 for (int i = 0; i < spin; i++) Pause();334 if (spin < spin_end) spin += spin;335 else spin_counter++;336 } else if (yield_counter < yield_count) {337 // after linear backoff yield yield_count times338 yield_counter++;339 yield();340 } else { break; }341 }342 343 // block until signalled344 while (block(this)) if(try_lock_contention(this)) return true;345 346 // this should never be reached as block(this) always returns true347 return false;348 }349 350 static inline bool lock_improved(linear_backoff_then_block_lock & this) with(this) {351 // if owner just return352 if (active_thread() == owner) return true;353 size_t compare_val = 0;354 int spin = spin_start;355 // linear backoff356 for( ;; ) {357 compare_val = 0;358 if (internal_try_lock(this, compare_val)) return true;359 if (2 == compare_val) break;360 for (int i = 0; i < spin; i++) Pause();361 if (spin >= spin_end) break;362 spin += spin;363 }364 365 // linear backoff bounded by spin_count366 spin = spin_start;367 int spin_counter = 0;368 int yield_counter = 0;369 for ( ;; ) {370 compare_val = 0;371 if(internal_try_lock(this, compare_val)) return true;372 if (2 == compare_val) break;373 if(spin_counter < spin_count) {374 for (int i = 0; i < spin; i++) Pause();375 if (spin < spin_end) spin += spin;376 else spin_counter++;377 } else if (yield_counter < yield_count) {378 // after linear backoff yield yield_count times379 yield_counter++;380 yield();381 } else { break; }382 }383 384 326 if(2 != compare_val && try_lock_contention(this)) return true; 385 327 // block until signalled … … 402 344 static inline void on_notify(linear_backoff_then_block_lock & this, struct thread$ * t ) { unpark(t); } 403 345 static inline size_t on_wait(linear_backoff_then_block_lock & this) { unlock(this); return 0; } 404 static inline void on_wakeup(linear_backoff_then_block_lock & this, size_t recursion ) { lock _improved(this); }346 static inline void on_wakeup(linear_backoff_then_block_lock & this, size_t recursion ) { lock(this); } 405 347 406 348 //----------------------------------------------------------------------------- -
libcfa/src/concurrency/monitor.cfa
rdd1cc02 r5a40e4e 367 367 368 368 // __cfaabi_dbg_print_safe( "MGUARD : entered\n" ); 369 } 370 371 void ?{}( monitor_guard_t & this, monitor$ * m [], __lock_size_t count ) { 372 this{ m, count, 0p }; 369 373 } 370 374 … … 986 990 } 987 991 992 //----------------------------------------------------------------------------- 993 // Enter routine for mutex stmt 994 // Can't be accepted since a mutex stmt is effectively an anonymous routine 995 // Thus we do not need a monitor group 996 void lock( monitor$ * this ) { 997 thread$ * thrd = active_thread(); 998 999 // Lock the monitor spinlock 1000 lock( this->lock __cfaabi_dbg_ctx2 ); 1001 1002 __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner); 1003 1004 if( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) { 1005 abort( "Attempt by thread \"%.256s\" (%p) to access joined monitor %p.", thrd->self_cor.name, thrd, this ); 1006 } 1007 else if( !this->owner ) { 1008 // No one has the monitor, just take it 1009 __set_owner( this, thrd ); 1010 1011 __cfaabi_dbg_print_safe( "Kernel : mon is free \n" ); 1012 } 1013 else if( this->owner == thrd) { 1014 // We already have the monitor, just note how many times we took it 1015 this->recursion += 1; 1016 1017 __cfaabi_dbg_print_safe( "Kernel : mon already owned \n" ); 1018 } 1019 else { 1020 __cfaabi_dbg_print_safe( "Kernel : blocking \n" ); 1021 1022 // Some one else has the monitor, wait in line for it 1023 /* paranoid */ verify( thrd->link.next == 0p ); 1024 append( this->entry_queue, thrd ); 1025 /* paranoid */ verify( thrd->link.next == 1p ); 1026 1027 unlock( this->lock ); 1028 park(); 1029 1030 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this); 1031 1032 /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this ); 1033 return; 1034 } 1035 1036 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this); 1037 1038 /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this ); 1039 /* paranoid */ verify( this->lock.lock ); 1040 1041 // Release the lock and leave 1042 unlock( this->lock ); 1043 return; 1044 } 1045 1046 // Leave routine for mutex stmt 1047 // Is just a wrapper around __leave for the is_lock trait to see 1048 void unlock( monitor$ * this ) { __leave( this ); } 1049 988 1050 // Local Variables: // 989 1051 // mode: c // -
libcfa/src/concurrency/monitor.hfa
rdd1cc02 r5a40e4e 48 48 49 49 void ?{}( monitor_guard_t & this, monitor$ ** m, __lock_size_t count, void (*func)() ); 50 void ?{}( monitor_guard_t & this, monitor$ ** m, __lock_size_t count ); 50 51 void ^?{}( monitor_guard_t & this ); 51 52 … … 148 149 void __waitfor_internal( const __waitfor_mask_t & mask, int duration ); 149 150 151 // lock and unlock routines for mutex statements to use 152 void lock( monitor$ * this ); 153 void unlock( monitor$ * this ); 154 150 155 // Local Variables: // 151 156 // mode: c // -
libcfa/src/concurrency/thread.cfa
rdd1cc02 r5a40e4e 34 34 preempted = __NO_PREEMPTION; 35 35 corctx_flag = false; 36 disable_interrupts(); 36 37 last_cpu = __kernel_getcpu(); 38 enable_interrupts(); 37 39 curr_cor = &self_cor; 38 40 self_mon.owner = &this; -
libcfa/src/fstream.cfa
rdd1cc02 r5a40e4e 124 124 void open( ofstream & os, const char name[], const char mode[] ) { 125 125 FILE * file = fopen( name, mode ); 126 #ifdef __CFA_DEBUG__126 // #ifdef __CFA_DEBUG__ 127 127 if ( file == 0p ) { 128 128 throw (Open_Failure){ os }; 129 129 // abort | IO_MSG "open output file \"" | name | "\"" | nl | strerror( errno ); 130 130 } // if 131 #endif // __CFA_DEBUG__131 // #endif // __CFA_DEBUG__ 132 132 (os){ file }; 133 133 } // open … … 262 262 void open( ifstream & is, const char name[], const char mode[] ) { 263 263 FILE * file = fopen( name, mode ); 264 #ifdef __CFA_DEBUG__264 // #ifdef __CFA_DEBUG__ 265 265 if ( file == 0p ) { 266 266 throw (Open_Failure){ is }; 267 267 // abort | IO_MSG "open input file \"" | name | "\"" | nl | strerror( errno ); 268 268 } // if 269 #endif // __CFA_DEBUG__269 // #endif // __CFA_DEBUG__ 270 270 is.file$ = file; 271 271 } // open -
libcfa/src/heap.cfa
rdd1cc02 r5a40e4e 10 10 // Created On : Tue Dec 19 21:58:35 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat May 22 08:46:39202113 // Update Count : 10 3612 // Last Modified On : Mon Aug 9 19:03:02 2021 13 // Update Count : 1040 14 14 // 15 15 … … 102 102 } // prtUnfreed 103 103 104 extern int cfa_main_returned; // from bootloader.cf 104 105 extern "C" { 105 106 void heapAppStart() { // called by __cfaabi_appready_startup … … 109 110 void heapAppStop() { // called by __cfaabi_appready_startdown 110 111 fclose( stdin ); fclose( stdout ); 111 prtUnfreed();112 if ( cfa_main_returned ) prtUnfreed(); // do not check unfreed storage if exit called 112 113 } // heapAppStop 113 114 } // extern "C" -
libcfa/src/memory.cfa
rdd1cc02 r5a40e4e 155 155 156 156 forall(T &) 157 T * release(unique_ptr(T) & this) { 158 T * data = this.data; 159 this.data = 0p; 160 return data; 161 } 162 163 forall(T &) 157 164 int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that) { 158 165 return this.data == that.data; -
libcfa/src/memory.hfa
rdd1cc02 r5a40e4e 94 94 95 95 forall(T &) 96 T * release(unique_ptr(T) & this); 97 98 forall(T &) 96 99 int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that); 97 100 forall(T &)
Note: See TracChangeset
for help on using the changeset viewer.