Ignore:
Timestamp:
Jul 13, 2017, 4:16:21 PM (7 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:
4b234f0, 994d080
Parents:
578e6037 (diff), d6ff3ff (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:

Merge branch 'master' of plg2:software/cfa/cfa-cc

File:
1 edited

Legend:

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

    r578e6037 r24fc196  
    180180
    181181static inline bool preemption_ready() {
    182         return disable_preempt_count == 0;
     182        return disable_preempt_count == 0 && !preemption_in_progress;
    183183}
    184184
     
    218218
    219219void kernel_stop_preemption() {
     220        LIB_DEBUG_PRINT_SAFE("Kernel : Preemption stopping\n");
     221
    220222        sigset_t mask;
    221223        sigfillset( &mask );
    222224        sigprocmask( SIG_BLOCK, &mask, NULL );
    223225
    224         pthread_kill( alarm_thread, SIGINT );
     226        sigval val = { 1 };
     227        pthread_sigqueue( alarm_thread, SIGALRM, val );
    225228        pthread_join( alarm_thread, NULL );
    226229        LIB_DEBUG_PRINT_SAFE("Kernel : Preemption stopped\n");
     
    247250        LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); )
    248251        if( preemption_ready() ) {
     252                preemption_in_progress = true;
    249253                signal_unblock( SIGUSR1 );
     254                this_processor->pending_preemption = false;
     255                preemption_in_progress = false;
    250256                BlockInternal( (thread_desc*)this_thread );
    251257        }
     
    254260        }
    255261}
    256 
    257 // void sigHandler_alarm( __CFA_SIGPARMS__ ) {
    258 //      LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); )
    259 //      verify( this_processor == systemProcessor );
    260 
    261 //      if( try_lock( &systemProcessor->alarm_lock DEBUG_CTX2 ) ) {
    262 //              tick_preemption();
    263 //              systemProcessor->pending_alarm = false;
    264 //              unlock( &systemProcessor->alarm_lock );
    265 //      }
    266 //      else {
    267 //              defer_alarm();
    268 //      }
    269 
    270 //      signal_unblock( SIGALRM );
    271 
    272 //      if( preemption_ready() && this_processor->pending_preemption ) {
    273 
    274 //              this_processor->pending_preemption = false;
    275 //              BlockInternal( (thread_desc*)this_thread );
    276 //      }
    277 // }
    278262
    279263void * alarm_loop( __attribute__((unused)) void * args ) {
     
    281265        sigemptyset( &mask );
    282266        sigaddset( &mask, SIGALRM );
    283         sigaddset( &mask, SIGUSR2 );
    284         sigaddset( &mask, SIGINT  );
    285267
    286268        if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
     
    289271
    290272        while( true ) {
    291                 int sig;
    292                 if( sigwait( &mask, &sig ) != 0  ) {
     273                siginfo_t info;
     274                int sig = sigwaitinfo( &mask, &info );
     275                if( sig < 0 ) {
    293276                        abortf( "internal error, sigwait" );
    294277                }
    295 
    296                 switch( sig) {
    297                         case SIGALRM:
     278                else if( sig == SIGALRM )
     279                {
     280                        LIB_DEBUG_PRINT_SAFE("Kernel : Caught signal %d (%d)\n", sig, info.si_value.sival_int );
     281                        if( info.si_value.sival_int == 0 )
     282                        {
    298283                                LIB_DEBUG_PRINT_SAFE("Kernel : Preemption thread tick\n");
    299284                                lock( &systemProcessor->alarm_lock DEBUG_CTX2 );
    300285                                tick_preemption();
    301286                                unlock( &systemProcessor->alarm_lock );
     287                        }
     288                        else if( info.si_value.sival_int == 1 )
     289                        {
    302290                                break;
    303                         case SIGUSR2:
    304                                 //TODO other actions
    305                                 break;
    306                         case SIGINT:
    307                                 LIB_DEBUG_PRINT_SAFE("Kernel : Preemption thread stopping\n");
    308                                 return NULL;
    309                         default:
    310                                 abortf( "internal error, sigwait returned sig %d", sig );
    311                                 break;
    312                 }
    313         }
     291                        }
     292                }
     293                else
     294                {
     295                        LIB_DEBUG_PRINT_SAFE("Kernel : Unexpected signal %d (%d)\n", sig, info.si_value.sival_int);
     296                }
     297        }
     298
     299        LIB_DEBUG_PRINT_SAFE("Kernel : Preemption thread stopping\n");
     300        return NULL;
    314301}
    315302
Note: See TracChangeset for help on using the changeset viewer.