Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel.cfa

    r56e5b24 r1f45c7d  
    110110#endif
    111111
    112 extern thread$ * mainThread;
     112extern $thread * mainThread;
    113113extern processor * mainProcessor;
    114114
    115115//-----------------------------------------------------------------------------
    116116// Kernel Scheduling logic
    117 static thread$ * __next_thread(cluster * this);
    118 static thread$ * __next_thread_slow(cluster * this);
    119 static inline bool __must_unpark( thread$ * thrd ) __attribute((nonnull(1)));
    120 static void __run_thread(processor * this, thread$ * dst);
     117static $thread * __next_thread(cluster * this);
     118static $thread * __next_thread_slow(cluster * this);
     119static inline bool __must_unpark( $thread * thrd ) __attribute((nonnull(1)));
     120static void __run_thread(processor * this, $thread * dst);
    121121static void __wake_one(cluster * cltr);
    122122
     
    181181                __cfadbg_print_safe(runtime_core, "Kernel : core %p started\n", this);
    182182
    183                 thread$ * readyThread = 0p;
     183                $thread * readyThread = 0p;
    184184                MAIN_LOOP:
    185185                for() {
     
    231231                                __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle);
    232232
    233                                 {
    234                                         eventfd_t val;
    235                                         ssize_t ret = read( this->idle, &val, sizeof(val) );
    236                                         if(ret < 0) {
    237                                                 switch((int)errno) {
    238                                                 case EAGAIN:
    239                                                 #if EAGAIN != EWOULDBLOCK
    240                                                         case EWOULDBLOCK:
    241                                                 #endif
    242                                                 case EINTR:
    243                                                         // No need to do anything special here, just assume it's a legitimate wake-up
    244                                                         break;
    245                                                 default:
    246                                                         abort( "KERNEL : internal error, read failure on idle eventfd, error(%d) %s.", (int)errno, strerror( (int)errno ) );
    247                                                 }
    248                                         }
    249                                 }
     233                                __disable_interrupts_hard();
     234                                eventfd_t val;
     235                                eventfd_read( this->idle, &val );
     236                                __enable_interrupts_hard();
    250237
    251238                                #if !defined(__CFA_NO_STATISTICS__)
     
    401388// runThread runs a thread by context switching
    402389// from the processor coroutine to the target thread
    403 static void __run_thread(processor * this, thread$ * thrd_dst) {
     390static void __run_thread(processor * this, $thread * thrd_dst) {
    404391        /* paranoid */ verify( ! __preemption_enabled() );
    405392        /* paranoid */ verifyf( thrd_dst->state == Ready || thrd_dst->preempted != __NO_PREEMPTION, "state : %d, preempted %d\n", thrd_dst->state, thrd_dst->preempted);
     
    419406        __cfadbg_print_safe(runtime_core, "Kernel : core %p running thread %p (%s)\n", this, thrd_dst, thrd_dst->self_cor.name);
    420407
    421         coroutine$ * proc_cor = get_coroutine(this->runner);
     408        $coroutine * proc_cor = get_coroutine(this->runner);
    422409
    423410        // set state of processor coroutine to inactive
     
    438425                /* paranoid */ verify( thrd_dst->context.SP );
    439426                /* paranoid */ verify( thrd_dst->state != Halted );
    440                 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); // add escape condition if we are setting up the processor
    441                 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too large.\n", thrd_dst ); // add escape condition if we are setting up the processor
     427                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); // add escape condition if we are setting up the processor
     428                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too large.\n", thrd_dst ); // add escape condition if we are setting up the processor
    442429                /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary );
    443430
     
    451438
    452439                /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary );
    453                 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too large.\n", thrd_dst );
    454                 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too small.\n", thrd_dst );
     440                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->corctx_flag, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too large.\n", thrd_dst );
     441                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->corctx_flag, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too small.\n", thrd_dst );
    455442                /* paranoid */ verify( thrd_dst->context.SP );
    456443                /* paranoid */ verify( thrd_dst->curr_cluster == this->cltr );
     
    518505void returnToKernel() {
    519506        /* paranoid */ verify( ! __preemption_enabled() );
    520         coroutine$ * proc_cor = get_coroutine(kernelTLS().this_processor->runner);
    521         thread$ * thrd_src = kernelTLS().this_thread;
     507        $coroutine * proc_cor = get_coroutine(kernelTLS().this_processor->runner);
     508        $thread * thrd_src = kernelTLS().this_thread;
    522509
    523510        __STATS( thrd_src->last_proc = kernelTLS().this_processor; )
     
    547534
    548535        /* paranoid */ verify( ! __preemption_enabled() );
    549         /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ) || thrd_src->corctx_flag, "ERROR : Returning thread$ %p has been corrupted.\n StackPointer too small.\n", thrd_src );
    550         /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit) || thrd_src->corctx_flag, "ERROR : Returning thread$ %p has been corrupted.\n StackPointer too large.\n", thrd_src );
     536        /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ) || thrd_src->corctx_flag, "ERROR : Returning $thread %p has been corrupted.\n StackPointer too small.\n", thrd_src );
     537        /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit) || thrd_src->corctx_flag, "ERROR : Returning $thread %p has been corrupted.\n StackPointer too large.\n", thrd_src );
    551538}
    552539
     
    554541// Scheduler routines
    555542// KERNEL ONLY
    556 static void __schedule_thread( thread$ * thrd ) {
     543static void __schedule_thread( $thread * thrd ) {
    557544        /* paranoid */ verify( ! __preemption_enabled() );
    558545        /* paranoid */ verify( ready_schedule_islocked());
     
    602589}
    603590
    604 void schedule_thread$( thread$ * thrd ) {
     591void schedule_thread$( $thread * thrd ) {
    605592        ready_schedule_lock();
    606593                __schedule_thread( thrd );
     
    609596
    610597// KERNEL ONLY
    611 static inline thread$ * __next_thread(cluster * this) with( *this ) {
     598static inline $thread * __next_thread(cluster * this) with( *this ) {
    612599        /* paranoid */ verify( ! __preemption_enabled() );
    613600
    614601        ready_schedule_lock();
    615                 thread$ * thrd = pop_fast( this );
     602                $thread * thrd = pop_fast( this );
    616603        ready_schedule_unlock();
    617604
     
    621608
    622609// KERNEL ONLY
    623 static inline thread$ * __next_thread_slow(cluster * this) with( *this ) {
     610static inline $thread * __next_thread_slow(cluster * this) with( *this ) {
    624611        /* paranoid */ verify( ! __preemption_enabled() );
    625612
    626613        ready_schedule_lock();
    627                 thread$ * thrd;
     614                $thread * thrd;
    628615                for(25) {
    629616                        thrd = pop_slow( this );
     
    639626}
    640627
    641 static inline bool __must_unpark( thread$ * thrd ) {
     628static inline bool __must_unpark( $thread * thrd ) {
    642629        int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST);
    643630        switch(old_ticket) {
     
    655642}
    656643
    657 void __kernel_unpark( thread$ * thrd ) {
     644void __kernel_unpark( $thread * thrd ) {
    658645        /* paranoid */ verify( ! __preemption_enabled() );
    659646        /* paranoid */ verify( ready_schedule_islocked());
     
    670657}
    671658
    672 void unpark( thread$ * thrd ) {
     659void unpark( $thread * thrd ) {
    673660        if( !thrd ) return;
    674661
     
    694681        // Should never return
    695682        void __cfactx_thrd_leave() {
    696                 thread$ * thrd = active_thread();
    697                 monitor$ * this = &thrd->self_mon;
     683                $thread * thrd = active_thread();
     684                $monitor * this = &thrd->self_mon;
    698685
    699686                // Lock the monitor now
     
    707694                /* paranoid */ verify( kernelTLS().this_thread == thrd );
    708695                /* paranoid */ verify( thrd->context.SP );
    709                 /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) > ((uintptr_t)__get_stack(thrd->curr_cor)->limit), "ERROR : thread$ %p has been corrupted.\n StackPointer too large.\n", thrd );
    710                 /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) < ((uintptr_t)__get_stack(thrd->curr_cor)->base ), "ERROR : thread$ %p has been corrupted.\n StackPointer too small.\n", thrd );
     696                /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) > ((uintptr_t)__get_stack(thrd->curr_cor)->limit), "ERROR : $thread %p has been corrupted.\n StackPointer too large.\n", thrd );
     697                /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) < ((uintptr_t)__get_stack(thrd->curr_cor)->base ), "ERROR : $thread %p has been corrupted.\n StackPointer too small.\n", thrd );
    711698
    712699                thrd->state = Halting;
     
    726713bool force_yield( __Preemption_Reason reason ) {
    727714        __disable_interrupts_checked();
    728                 thread$ * thrd = kernelTLS().this_thread;
     715                $thread * thrd = kernelTLS().this_thread;
    729716                /* paranoid */ verify(thrd->state == Active);
    730717
     
    838825//=============================================================================================
    839826void __kernel_abort_msg( char * abort_text, int abort_text_size ) {
    840         thread$ * thrd = __cfaabi_tls.this_thread;
     827        $thread * thrd = __cfaabi_tls.this_thread;
    841828
    842829        if(thrd) {
Note: See TracChangeset for help on using the changeset viewer.