Changeset 2ac095d for src/libcfa/concurrency
- Timestamp:
- Jun 23, 2017, 11:22:59 AM (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:
- 7bbba76
- Parents:
- d43cd01
- Location:
- src/libcfa/concurrency
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/alarm.c
rd43cd01 r2ac095d 24 24 } 25 25 26 #include "libhdr.h" 27 26 28 #include "alarm.h" 27 29 #include "kernel_private.h" 28 #include "libhdr.h"29 30 #include "preemption.h" 30 31 … … 154 155 disable_interrupts(); 155 156 verify( !systemProcessor->pending_alarm ); 156 lock( &systemProcessor->alarm_lock , __PRETTY_FUNCTION__);157 lock( &systemProcessor->alarm_lock DEBUG_CTX2 ); 157 158 { 158 159 verify( validate( &systemProcessor->alarms ) ); … … 169 170 unlock( &systemProcessor->alarm_lock ); 170 171 this->set = true; 171 enable_interrupts( __PRETTY_FUNCTION__);172 enable_interrupts( DEBUG_CTX ); 172 173 } 173 174 … … 175 176 // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : unregister %p start\n", this ); 176 177 disable_interrupts(); 177 lock( &systemProcessor->alarm_lock , __PRETTY_FUNCTION__);178 lock( &systemProcessor->alarm_lock DEBUG_CTX2 ); 178 179 { 179 180 verify( validate( &systemProcessor->alarms ) ); … … 181 182 } 182 183 unlock( &systemProcessor->alarm_lock ); 183 disable_interrupts();184 enable_interrupts( DEBUG_CTX ); 184 185 this->set = false; 185 186 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Kernel : unregister %p end\n", this ); -
src/libcfa/concurrency/invoke.c
rd43cd01 r2ac095d 31 31 extern void __leave_thread_monitor( struct thread_desc * this ); 32 32 extern void disable_interrupts(); 33 extern void enable_interrupts( const char *);33 extern void enable_interrupts( DEBUG_CTX_PARAM ); 34 34 35 35 void CtxInvokeCoroutine( … … 71 71 72 72 // Officially start the thread by enabling preemption 73 enable_interrupts( __PRETTY_FUNCTION__);73 enable_interrupts( DEBUG_CTX ); 74 74 75 75 // Call the main of the thread -
src/libcfa/concurrency/kernel
rd43cd01 r2ac095d 28 28 //----------------------------------------------------------------------------- 29 29 // Locks 30 bool try_lock( spinlock * 31 #ifdef __CFA_DEBUG__ 32 , const char * caller 33 #endif 34 ); 35 36 void lock( spinlock * 37 #ifdef __CFA_DEBUG__ 38 , const char * caller 39 #endif 40 ); 41 42 void unlock( spinlock * ); 30 bool try_lock( spinlock * DEBUG_CTX_PARAM2 ); 31 void lock ( spinlock * DEBUG_CTX_PARAM2 ); 32 void unlock ( spinlock * ); 43 33 44 34 struct signal_once { … … 78 68 unsigned short thrd_count; 79 69 }; 80 static inline void ?{}(FinishAction * this) { 70 static inline void ?{}(FinishAction * this) { 81 71 this->action_code = No_Action; 82 72 this->thrd = NULL; … … 89 79 cluster * cltr; 90 80 pthread_t kernel_thread; 91 81 92 82 signal_once terminated; 93 83 volatile bool is_terminated; -
src/libcfa/concurrency/kernel.c
rd43cd01 r2ac095d 15 15 // 16 16 17 #include "startup.h" 18 19 //Start and stop routine for the kernel, declared first to make sure they run first 20 void kernel_startup(void) __attribute__(( constructor( STARTUP_PRIORITY_KERNEL ) )); 21 void kernel_shutdown(void) __attribute__(( destructor ( STARTUP_PRIORITY_KERNEL ) )); 22 23 //Header 24 #include "kernel_private.h" 17 #include "libhdr.h" 25 18 26 19 //C Includes … … 35 28 36 29 //CFA Includes 37 #include " libhdr.h"30 #include "kernel_private.h" 38 31 #include "preemption.h" 32 #include "startup.h" 39 33 40 34 //Private includes 41 35 #define __CFA_INVOKE_PRIVATE__ 42 36 #include "invoke.h" 37 38 //Start and stop routine for the kernel, declared first to make sure they run first 39 void kernel_startup(void) __attribute__(( constructor( STARTUP_PRIORITY_KERNEL ) )); 40 void kernel_shutdown(void) __attribute__(( destructor ( STARTUP_PRIORITY_KERNEL ) )); 43 41 44 42 //----------------------------------------------------------------------------- … … 369 367 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); 370 368 371 lock( &systemProcessor->proc.cltr->lock , __PRETTY_FUNCTION__);369 lock( &systemProcessor->proc.cltr->lock DEBUG_CTX2 ); 372 370 append( &systemProcessor->proc.cltr->ready_queue, thrd ); 373 371 unlock( &systemProcessor->proc.cltr->lock ); … … 378 376 thread_desc * nextThread(cluster * this) { 379 377 verify( disable_preempt_count > 0 ); 380 lock( &this->lock , __PRETTY_FUNCTION__);378 lock( &this->lock DEBUG_CTX2 ); 381 379 thread_desc * head = pop_head( &this->ready_queue ); 382 380 unlock( &this->lock ); … … 390 388 suspend(); 391 389 verify( disable_preempt_count > 0 ); 392 enable_interrupts( __PRETTY_FUNCTION__);390 enable_interrupts( DEBUG_CTX ); 393 391 } 394 392 … … 402 400 verify( disable_preempt_count > 0 ); 403 401 404 enable_interrupts( __PRETTY_FUNCTION__);402 enable_interrupts( DEBUG_CTX ); 405 403 } 406 404 … … 415 413 verify( disable_preempt_count > 0 ); 416 414 417 enable_interrupts( __PRETTY_FUNCTION__);415 enable_interrupts( DEBUG_CTX ); 418 416 } 419 417 … … 428 426 verify( disable_preempt_count > 0 ); 429 427 430 enable_interrupts( __PRETTY_FUNCTION__);428 enable_interrupts( DEBUG_CTX ); 431 429 } 432 430 … … 441 439 verify( disable_preempt_count > 0 ); 442 440 443 enable_interrupts( __PRETTY_FUNCTION__);441 enable_interrupts( DEBUG_CTX ); 444 442 } 445 443 … … 456 454 verify( disable_preempt_count > 0 ); 457 455 458 enable_interrupts( __PRETTY_FUNCTION__);456 enable_interrupts( DEBUG_CTX ); 459 457 } 460 458 … … 510 508 LIB_DEBUG_PRINT_SAFE("Kernel : Started\n--------------------------------------------------\n\n"); 511 509 512 enable_interrupts( __PRETTY_FUNCTION__);510 enable_interrupts( DEBUG_CTX ); 513 511 } 514 512 … … 548 546 // abort cannot be recursively entered by the same or different processors because all signal handlers return when 549 547 // the globalAbort flag is true. 550 lock( &kernel_abort_lock , __PRETTY_FUNCTION__);548 lock( &kernel_abort_lock DEBUG_CTX2 ); 551 549 552 550 // first task to abort ? … … 586 584 extern "C" { 587 585 void __lib_debug_acquire() { 588 lock( &kernel_debug_lock, __PRETTY_FUNCTION__);586 lock( &kernel_debug_lock DEBUG_CTX2 ); 589 587 } 590 588 591 589 void __lib_debug_release() { 592 unlock( &kernel_debug_lock);590 unlock( &kernel_debug_lock ); 593 591 } 594 592 } … … 606 604 } 607 605 608 bool try_lock( spinlock * this , const char * caller) {606 bool try_lock( spinlock * this DEBUG_CTX_PARAM2 ) { 609 607 bool ret = this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0; 610 this->prev = caller;608 LIB_DEBUG_DO( this->prev = caller; ) 611 609 return ret; 612 610 } 613 611 614 void lock( spinlock * this , const char * caller) {612 void lock( spinlock * this DEBUG_CTX_PARAM2 ) { 615 613 for ( unsigned int i = 1;; i += 1 ) { 616 614 if ( this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0 ) break; 617 615 } 618 this->prev = caller;616 LIB_DEBUG_DO( this->prev = caller; ) 619 617 } 620 618 … … 631 629 632 630 void wait( signal_once * this ) { 633 lock( &this->lock , __PRETTY_FUNCTION__);631 lock( &this->lock DEBUG_CTX2 ); 634 632 if( !this->cond ) { 635 633 append( &this->blocked, (thread_desc*)this_thread ); … … 642 640 643 641 void signal( signal_once * this ) { 644 lock( &this->lock , __PRETTY_FUNCTION__);642 lock( &this->lock DEBUG_CTX2 ); 645 643 { 646 644 this->cond = true; … … 651 649 ScheduleThread( it ); 652 650 } 653 enable_interrupts( __PRETTY_FUNCTION__);651 enable_interrupts( DEBUG_CTX ); 654 652 } 655 653 unlock( &this->lock ); -
src/libcfa/concurrency/kernel_private.h
rd43cd01 r2ac095d 18 18 #define KERNEL_PRIVATE_H 19 19 20 #include "libhdr.h" 21 20 22 #include "kernel" 21 23 #include "thread" … … 23 25 #include "alarm.h" 24 26 25 #include "libhdr.h"26 27 27 28 //----------------------------------------------------------------------------- … … 31 32 void disable_interrupts(); 32 33 void enable_interrupts_noRF(); 33 void enable_interrupts( const char *);34 void enable_interrupts( DEBUG_CTX_PARAM ); 34 35 } 35 36 … … 40 41 disable_interrupts(); 41 42 ScheduleThread( thrd ); 42 enable_interrupts( __PRETTY_FUNCTION__);43 enable_interrupts( DEBUG_CTX ); 43 44 } 44 45 thread_desc * nextThread(cluster * this); -
src/libcfa/concurrency/monitor.c
rd43cd01 r2ac095d 19 19 #include <stdlib> 20 20 21 #include "libhdr.h" 21 22 #include "kernel_private.h" 22 #include "libhdr.h"23 23 24 24 //----------------------------------------------------------------------------- … … 45 45 extern "C" { 46 46 void __enter_monitor_desc( monitor_desc * this ) { 47 lock( &this->lock , __PRETTY_FUNCTION__);47 lock( &this->lock DEBUG_CTX2 ); 48 48 thread_desc * thrd = this_thread; 49 49 … … 66 66 67 67 //BlockInternal will unlock spinlock, no need to unlock ourselves 68 return; 68 return; 69 69 } 70 70 … … 76 76 // TODO 77 77 void __leave_monitor_desc( monitor_desc * this ) { 78 lock( &this->lock , __PRETTY_FUNCTION__);78 lock( &this->lock DEBUG_CTX2 ); 79 79 80 80 // LIB_DEBUG_PRINT_SAFE("%p Leaving %p (o: %p, r: %i). ", this_thread, this, this->owner, this->recursion); … … 104 104 void __leave_thread_monitor( thread_desc * thrd ) { 105 105 monitor_desc * this = &thrd->mon; 106 lock( &this->lock , __PRETTY_FUNCTION__);106 lock( &this->lock DEBUG_CTX2 ); 107 107 108 108 disable_interrupts(); … … 260 260 261 261 unsigned short count = this->monitor_count; 262 262 263 263 //Some more checking in debug 264 264 LIB_DEBUG_DO( … … 354 354 355 355 uintptr_t front( condition * this ) { 356 verifyf( !is_empty(this), 356 verifyf( !is_empty(this), 357 357 "Attempt to access user data on an empty condition.\n" 358 358 "Possible cause is not checking if the condition is empty before reading stored data." … … 422 422 static inline void lock_all( spinlock ** locks, unsigned short count ) { 423 423 for( int i = 0; i < count; i++ ) { 424 lock( locks[i] , __PRETTY_FUNCTION__);424 lock( locks[i] DEBUG_CTX2 ); 425 425 } 426 426 } … … 429 429 for( int i = 0; i < count; i++ ) { 430 430 spinlock * l = &source[i]->lock; 431 lock( l , __PRETTY_FUNCTION__);431 lock( l DEBUG_CTX2 ); 432 432 if(locks) locks[i] = l; 433 433 } -
src/libcfa/concurrency/preemption.c
rd43cd01 r2ac095d 15 15 // 16 16 17 #include "libhdr.h" 17 18 #include "preemption.h" 18 19 19 20 20 extern "C" { … … 33 33 #include "fstream" 34 34 #endif 35 #include "libhdr.h"36 35 37 36 #define __CFA_DEFAULT_PREEMPTION__ 10000 … … 167 166 168 167 void enable_interrupts_noRF() { 169 unsigned short prev = __atomic_fetch_add_2( &disable_preempt_count, -1, __ATOMIC_SEQ_CST );168 __attribute__((unused)) unsigned short prev = __atomic_fetch_add_2( &disable_preempt_count, -1, __ATOMIC_SEQ_CST ); 170 169 verify( prev != (unsigned short) 0 ); 171 170 } 172 171 173 void enable_interrupts( const char * func) {172 void enable_interrupts( DEBUG_CTX_PARAM ) { 174 173 processor * proc = this_processor; 175 174 thread_desc * thrd = this_thread; … … 183 182 } 184 183 185 proc->last_enable = func;184 LIB_DEBUG_DO( proc->last_enable = caller; ) 186 185 } 187 186 } … … 238 237 // if( ((intptr_t)cxt->uc_mcontext.gregs[REG_RIP]) > 0xFFFFFF ) __debug_break(); 239 238 240 if( try_lock( &systemProcessor->alarm_lock , __PRETTY_FUNCTION__) ) {239 if( try_lock( &systemProcessor->alarm_lock DEBUG_CTX2 ) ) { 241 240 tick_preemption(); 242 241 unlock( &systemProcessor->alarm_lock ); -
src/libcfa/concurrency/thread.c
rd43cd01 r2ac095d 83 83 84 84 ScheduleThread(thrd_h); 85 enable_interrupts( __PRETTY_FUNCTION__);85 enable_interrupts( DEBUG_CTX ); 86 86 } 87 87
Note: See TracChangeset
for help on using the changeset viewer.