Changeset 4dad189


Ignore:
Timestamp:
Feb 8, 2018, 1:59:03 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
eb7f20c
Parents:
3d5f2ef1
Message:

Processor can no longer be destroyed from a thread that is running on said processor

Location:
src/libcfa/concurrency
Files:
3 edited

Legend:

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

    r3d5f2ef1 r4dad189  
    170170        if( ! do_terminate ) {
    171171                __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this);
    172                 do_terminate = true;
     172                terminate(&this);
    173173                P( terminated );
    174174                pthread_join( kernel_thread, NULL );
  • src/libcfa/concurrency/kernel_private.h

    r3d5f2ef1 r4dad189  
    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/preemption.c

    r3d5f2ef1 r4dad189  
    6767}
    6868
     69enum {
     70        PREEMPT_NORMAL    = 0,
     71        PREEMPT_TERMINATE = 1,
     72};
     73
    6974//=============================================================================================
    7075// Kernel Preemption logic
     
    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
     
    298311void sigHandler_ctxSwitch( __CFA_SIGPARMS__ ) {
    299312        __cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.CFA_REG_IP); )
     313
     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                        abortf( "internal error, signal value is %d", sfp->si_value.sival_int );
     325        }
    300326
    301327        // Check if it is safe to preempt here
Note: See TracChangeset for help on using the changeset viewer.