Ignore:
Timestamp:
Feb 9, 2018, 4:39:52 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
298ed08
Parents:
381fdee (diff), a722c7a (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.
Message:

fix conflicts

Location:
src/libcfa/concurrency
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/coroutine.c

    r381fdee rbede27b  
    1010// Created On       : Mon Nov 28 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:34:57 2017
    13 // Update Count     : 1
     12// Last Modified On : Thu Feb  8 16:10:31 2018
     13// Update Count     : 4
    1414//
    1515
     
    7777                __cfaabi_dbg_debug_do(
    7878                        if ( mprotect( this.storage, pageSize, PROT_READ | PROT_WRITE ) == -1 ) {
    79                                 abortf( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) );
     79                                abort( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) );
    8080                        }
    8181                );
     
    135135                __cfaabi_dbg_debug_do(
    136136                        if ( mprotect( storage, pageSize, PROT_NONE ) == -1 ) {
    137                                 abortf( "(uMachContext &)%p.createContext() : internal error, mprotect failure, error(%d) %s.", this, (int)errno, strerror( (int)errno ) );
     137                                abort( "(uMachContext &)%p.createContext() : internal error, mprotect failure, error(%d) %s.", this, (int)errno, strerror( (int)errno ) );
    138138                        } // if
    139139                );
    140140
    141141                if ( (intptr_t)storage == 0 ) {
    142                         abortf( "Attempt to allocate %d bytes of storage for coroutine or task execution-state but insufficient memory available.", size );
     142                        abort( "Attempt to allocate %zd bytes of storage for coroutine or task execution-state but insufficient memory available.", size );
    143143                } // if
    144144
  • src/libcfa/concurrency/invoke.c

    r381fdee rbede27b  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb  9 14:41:56 2018
    13 // Update Count     : 3
     12// Last Modified On : Fri Feb  9 16:37:42 2018
     13// Update Count     : 5
    1414//
    1515
     
    5151        //Final suspend, should never return
    5252        __leave_coroutine();
    53         abortf("Resumed dead coroutine");
     53        __cabi_abort( "Resumed dead coroutine" );
    5454}
    5555
     
    8181        //Final suspend, should never return
    8282        __leave_thread_monitor( thrd );
    83         abortf("Resumed dead thread");
     83        __cabi_abort( "Resumed dead thread" );
    8484}
    8585
  • src/libcfa/concurrency/kernel.c

    r381fdee rbede27b  
    168168        if( ! do_terminate ) {
    169169                __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this);
    170                 do_terminate = true;
     170                terminate(&this);
    171171                P( terminated );
    172172                pthread_join( kernel_thread, NULL );
  • src/libcfa/concurrency/kernel_private.h

    r381fdee rbede27b  
    6060void runThread(processor * this, thread_desc * dst);
    6161void finishRunning(processor * this);
     62void terminate(processor * this);
    6263void spin(processor * this, unsigned int * spin_count);
    6364
  • src/libcfa/concurrency/monitor.c

    r381fdee rbede27b  
    1010// Created On       : Thd Feb 23 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jul 31 14:59:05 2017
    13 // Update Count     : 3
     12// Last Modified On : Thu Feb  8 16:12:20 2018
     13// Update Count     : 4
    1414//
    1515
     
    8787                thread_desc * thrd = this_thread;
    8888
    89                 __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
     89                __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
    9090
    9191                if( !this->owner ) {
     
    9393                        set_owner( this, thrd );
    9494
    95                         __cfaabi_dbg_print_safe("Kernel :  mon is free \n");
     95                        __cfaabi_dbg_print_safe( "Kernel :  mon is free \n" );
    9696                }
    9797                else if( this->owner == thrd) {
     
    9999                        this->recursion += 1;
    100100
    101                         __cfaabi_dbg_print_safe("Kernel :  mon already owned \n");
     101                        __cfaabi_dbg_print_safe( "Kernel :  mon already owned \n" );
    102102                }
    103103                else if( is_accepted( this, group) ) {
     
    108108                        reset_mask( this );
    109109
    110                         __cfaabi_dbg_print_safe("Kernel :  mon accepts \n");
     110                        __cfaabi_dbg_print_safe( "Kernel :  mon accepts \n" );
    111111                }
    112112                else {
    113                         __cfaabi_dbg_print_safe("Kernel :  blocking \n");
     113                        __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
    114114
    115115                        // Some one else has the monitor, wait in line for it
     
    118118                        BlockInternal( &this->lock );
    119119
    120                         __cfaabi_dbg_print_safe("Kernel : %10p Entered  mon %p\n", thrd, this);
     120                        __cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
    121121
    122122                        // BlockInternal will unlock spinlock, no need to unlock ourselves
     
    124124                }
    125125
    126                 __cfaabi_dbg_print_safe("Kernel : %10p Entered  mon %p\n", thrd, this);
     126                __cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
    127127
    128128                // Release the lock and leave
     
    136136                thread_desc * thrd = this_thread;
    137137
    138                 __cfaabi_dbg_print_safe("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);
     138                __cfaabi_dbg_print_safe( "Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);
    139139
    140140
    141141                if( !this->owner ) {
    142                         __cfaabi_dbg_print_safe("Kernel : Destroying free mon %p\n", this);
     142                        __cfaabi_dbg_print_safe( "Kernel : Destroying free mon %p\n", this);
    143143
    144144                        // No one has the monitor, just take it
     
    151151                        // We already have the monitor... but where about to destroy it so the nesting will fail
    152152                        // Abort!
    153                         abortf("Attempt to destroy monitor %p by thread \"%.256s\" (%p) in nested mutex.");
     153                        abort( "Attempt to destroy monitor %p by thread \"%.256s\" (%p) in nested mutex." );
    154154                }
    155155
     
    158158                __monitor_group_t group = { &this, 1, func };
    159159                if( is_accepted( this, group) ) {
    160                         __cfaabi_dbg_print_safe("Kernel :  mon accepts dtor, block and signal it \n");
     160                        __cfaabi_dbg_print_safe( "Kernel :  mon accepts dtor, block and signal it \n" );
    161161
    162162                        // Wake the thread that is waiting for this
     
    177177                }
    178178                else {
    179                         __cfaabi_dbg_print_safe("Kernel :  blocking \n");
     179                        __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
    180180
    181181                        wait_ctx( this_thread, 0 )
     
    190190                }
    191191
    192                 __cfaabi_dbg_print_safe("Kernel : Destroying %p\n", this);
     192                __cfaabi_dbg_print_safe( "Kernel : Destroying %p\n", this);
    193193
    194194        }
     
    199199                lock( this->lock __cfaabi_dbg_ctx2 );
    200200
    201                 __cfaabi_dbg_print_safe("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
     201                __cfaabi_dbg_print_safe( "Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
    202202
    203203                verifyf( this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", this_thread, this->owner, this->recursion, this );
     
    209209                // it means we don't need to do anything
    210210                if( this->recursion != 0) {
    211                         __cfaabi_dbg_print_safe("Kernel :  recursion still %d\n", this->recursion);
     211                        __cfaabi_dbg_print_safe( "Kernel :  recursion still %d\n", this->recursion);
    212212                        unlock( this->lock );
    213213                        return;
     
    228228                __cfaabi_dbg_debug_do(
    229229                        if( this_thread != this->owner ) {
    230                                 abortf("Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, this_thread, this->owner);
     230                                abort( "Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, this_thread, this->owner);
    231231                        }
    232232                        if( this->recursion != 1 ) {
    233                                 abortf("Destroyed monitor %p has %d outstanding nested calls.\n", this, this->recursion - 1);
     233                                abort( "Destroyed monitor %p has %d outstanding nested calls.\n", this, this->recursion - 1);
    234234                        }
    235235                )
     
    256256                // If we haven't left the last level of recursion
    257257                // it must mean there is an error
    258                 if( this->recursion != 0) { abortf("Thread internal monitor has unbalanced recursion"); }
     258                if( this->recursion != 0) { abort( "Thread internal monitor has unbalanced recursion" ); }
    259259
    260260                // Fetch the next thread, can be null
     
    302302        (this_thread->monitors){m, count, func};
    303303
    304         // __cfaabi_dbg_print_safe("MGUARD : enter %d\n", count);
     304        // __cfaabi_dbg_print_safe( "MGUARD : enter %d\n", count);
    305305
    306306        // Enter the monitors in order
     
    308308        enter( group );
    309309
    310         // __cfaabi_dbg_print_safe("MGUARD : entered\n");
     310        // __cfaabi_dbg_print_safe( "MGUARD : entered\n" );
    311311}
    312312
     
    314314// Dtor for monitor guard
    315315void ^?{}( monitor_guard_t & this ) {
    316         // __cfaabi_dbg_print_safe("MGUARD : leaving %d\n", this.count);
     316        // __cfaabi_dbg_print_safe( "MGUARD : leaving %d\n", this.count);
    317317
    318318        // Leave the monitors in order
    319319        leave( this.m, this.count );
    320320
    321         // __cfaabi_dbg_print_safe("MGUARD : left\n");
     321        // __cfaabi_dbg_print_safe( "MGUARD : left\n" );
    322322
    323323        // Restore thread context
     
    427427                thread_desc * this_thrd = this_thread;
    428428                if ( this.monitor_count != this_thrd->monitors.size ) {
    429                         abortf( "Signal on condition %p made with different number of monitor(s), expected %i got %i", &this, this.monitor_count, this_thrd->monitors.size );
     429                        abort( "Signal on condition %p made with different number of monitor(s), expected %i got %i", &this, this.monitor_count, this_thrd->monitors.size );
    430430                }
    431431
    432432                for(int i = 0; i < this.monitor_count; i++) {
    433433                        if ( this.monitors[i] != this_thrd->monitors[i] ) {
    434                                 abortf( "Signal on condition %p made with different monitor, expected %p got %i", &this, this.monitors[i], this_thrd->monitors[i] );
     434                                abort( "Signal on condition %p made with different monitor, expected %p got %i", &this, this.monitors[i], this_thrd->monitors[i] );
    435435                        }
    436436                }
     
    534534        if(actual_count == 0) return;
    535535
    536         __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n");
     536        __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n" );
    537537
    538538        // Create storage for monitor context
     
    551551                        __acceptable_t& accepted = mask[index];
    552552                        if( accepted.is_dtor ) {
    553                                 __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n");
     553                                __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n" );
    554554                                verifyf( accepted.size == 1,  "ERROR: Accepted dtor has more than 1 mutex parameter." );
    555555
     
    563563                        }
    564564                        else {
    565                                 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, baton-passing\n");
     565                                __cfaabi_dbg_print_buffer_local( "Kernel : thread present, baton-passing\n" );
    566566
    567567                                // Create the node specific to this wait operation
     
    577577                                        }
    578578                                #endif
    579                                 __cfaabi_dbg_print_buffer_local( "\n");
     579                                __cfaabi_dbg_print_buffer_local( "\n" );
    580580
    581581                                // Set the owners to be the next thread
     
    588588                                monitor_restore;
    589589
    590                                 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n");
     590                                __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n" );
    591591                        }
    592592
     
    598598
    599599        if( duration == 0 ) {
    600                 __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n");
     600                __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n" );
    601601
    602602                unlock_all( locks, count );
     
    607607
    608608
    609         verifyf( duration < 0, "Timeout on waitfor statments not supported yet.");
    610 
    611         __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n");
     609        verifyf( duration < 0, "Timeout on waitfor statments not supported yet." );
     610
     611        __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n" );
    612612
    613613        // Create the node specific to this wait operation
     
    631631        monitor_restore;
    632632
    633         __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n");
     633        __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n" );
    634634
    635635        __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);
     
    640640
    641641static inline void set_owner( monitor_desc * this, thread_desc * owner ) {
    642         // __cfaabi_dbg_print_safe("Kernal :   Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );
     642        // __cfaabi_dbg_print_safe( "Kernal :   Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );
    643643
    644644        //Pass the monitor appropriately
     
    672672static inline thread_desc * next_thread( monitor_desc * this ) {
    673673        //Check the signaller stack
    674         __cfaabi_dbg_print_safe("Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
     674        __cfaabi_dbg_print_safe( "Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
    675675        __condition_criterion_t * urgent = pop( this->signal_stack );
    676676        if( urgent ) {
     
    814814        thread_desc * thrd = this_thread;
    815815        if( !this.monitors ) {
    816                 // __cfaabi_dbg_print_safe("Branding\n");
     816                // __cfaabi_dbg_print_safe( "Branding\n" );
    817817                assertf( thrd->monitors.data != NULL, "No current monitor to brand condition %p", thrd->monitors.data );
    818818                this.monitor_count = thrd->monitors.size;
  • src/libcfa/concurrency/preemption.c

    r381fdee rbede27b  
    1010// Created On       : Mon Jun 5 14:20:42 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb  9 14:42:34 2018
    13 // Update Count     : 25
     12// Last Modified On : Fri Feb  9 16:38:13 2018
     13// Update Count     : 14
    1414//
    1515
     
    6767}
    6868
     69enum {
     70        PREEMPT_NORMAL    = 0,
     71        PREEMPT_TERMINATE = 1,
     72};
     73
    6974//=============================================================================================
    7075// Kernel Preemption logic
     
    192197
    193198        if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) {
    194             abortf( "internal error, pthread_sigmask" );
     199            abort( "internal error, pthread_sigmask" );
    195200        }
    196201}
     
    203208
    204209        if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
    205             abortf( "internal error, pthread_sigmask" );
     210            abort( "internal error, pthread_sigmask" );
    206211        }
    207212}
     
    209214// kill wrapper : signal a processor
    210215static void preempt( processor * this ) {
    211         pthread_kill( this->kernel_thread, SIGUSR1 );
     216        sigval_t value = { PREEMPT_NORMAL };
     217        pthread_sigqueue( this->kernel_thread, SIGUSR1, value );
     218}
     219
     220// kill wrapper : signal a processor
     221void terminate(processor * this) {
     222        this->do_terminate = true;
     223        sigval_t value = { PREEMPT_TERMINATE };
     224        pthread_sigqueue( this->kernel_thread, SIGUSR1, value );
    212225}
    213226
     
    234247// Called from kernel_startup
    235248void kernel_start_preemption() {
    236         __cfaabi_dbg_print_safe("Kernel : Starting preemption\n");
     249        __cfaabi_dbg_print_safe( "Kernel : Starting preemption\n" );
    237250
    238251        // Start with preemption disabled until ready
     
    255268// Called from kernel_shutdown
    256269void kernel_stop_preemption() {
    257         __cfaabi_dbg_print_safe("Kernel : Preemption stopping\n");
     270        __cfaabi_dbg_print_safe( "Kernel : Preemption stopping\n" );
    258271
    259272        // Block all signals since we are already shutting down
     
    271284        // Preemption is now fully stopped
    272285
    273         __cfaabi_dbg_print_safe("Kernel : Preemption stopped\n");
     286        __cfaabi_dbg_print_safe( "Kernel : Preemption stopped\n" );
    274287}
    275288
     
    299312        __cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.CFA_REG_IP); )
    300313
     314        // SKULLDUGGERY: if a thread creates a processor and the immediately deletes it,
     315        // the interrupt that is supposed to force the kernel thread to preempt might arrive
     316        // before the kernel thread has even started running. When that happens an iterrupt
     317        // we a null 'this_processor' will be caught, just ignore it.
     318        if(!this_processor) return;
     319
     320        choose(sfp->si_value.sival_int) {
     321                case PREEMPT_NORMAL   : ;// Normal case, nothing to do here
     322                case PREEMPT_TERMINATE: verify(this_processor->do_terminate);
     323                default:
     324                        abort( "internal error, signal value is %d", sfp->si_value.sival_int );
     325        }
     326
    301327        // Check if it is safe to preempt here
    302328        if( !preemption_ready() ) { return; }
    303329
    304         __cfaabi_dbg_print_buffer_decl(" KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
     330        __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
    305331
    306332        preemption_in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
     
    322348
    323349        if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
    324             abortf( "internal error, pthread_sigmask" );
     350            abort( "internal error, pthread_sigmask" );
    325351        }
    326352
     
    339365                                        continue;
    340366                        case EINVAL :
    341                                         abortf("Timeout was invalid.");
     367                                        abort( "Timeout was invalid." );
    342368                                default:
    343                                         abortf("Unhandled error %d", err);
     369                                        abort( "Unhandled error %d", err);
    344370                        }
    345371                }
     
    348374                assertf(sig == SIGALRM, "Kernel Internal Error, sigwait: Unexpected signal %d (%d : %d)\n", sig, info.si_code, info.si_value.sival_int);
    349375
    350                 // __cfaabi_dbg_print_safe("Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );
     376                // __cfaabi_dbg_print_safe( "Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );
    351377                // Switch on the code (a.k.a. the sender) to
    352378                switch( info.si_code )
     
    356382                case SI_TIMER:
    357383                case SI_KERNEL:
    358                         // __cfaabi_dbg_print_safe("Kernel : Preemption thread tick\n");
     384                        // __cfaabi_dbg_print_safe( "Kernel : Preemption thread tick\n" );
    359385                        lock( event_kernel->lock __cfaabi_dbg_ctx2 );
    360386                        tick_preemption();
     
    370396
    371397EXIT:
    372         __cfaabi_dbg_print_safe("Kernel : Preemption thread stopping\n");
     398        __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" );
    373399        return NULL;
    374400}
Note: See TracChangeset for help on using the changeset viewer.