Ignore:
Timestamp:
Jul 4, 2017, 3:39:28 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:
cd17862
Parents:
8ee50281
Message:

Some cleanup before refactoring alarms

File:
1 edited

Legend:

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

    r8ee50281 r47ecf2b  
    179179                if( prev == 1 && proc->pending_preemption ) {
    180180                        proc->pending_preemption = false;
    181                         LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Executing deferred CtxSwitch on %p\n", this_processor );
    182181                        BlockInternal( thrd );
    183                         LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Executing deferred back\n" );
    184182                }
    185183
     
    189187
    190188static inline void signal_unblock( int sig ) {
    191         // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Processor : %p unblocking sig %i\n", this_processor, sig );
    192 
    193         // LIB_DEBUG_DO(
    194         //      sigset_t waiting;
    195         //      sigemptyset(&waiting);
    196         //      sigpending(&waiting);
    197         //      verify( !sigismember(&waiting, sig) );
    198         // )
     189        LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Unblock %d on %p\n", sig, this_processor );
    199190
    200191        sigset_t mask;
     
    202193        sigaddset( &mask, sig );
    203194
    204         if ( sigprocmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) {
    205             abortf( "internal error, sigprocmask" );
     195        if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) {
     196            abortf( "internal error, pthread_sigmask" );
    206197        } // if
    207198}
     199
     200// static inline void signal_block( int sig ) {
     201//      sigset_t mask;
     202//      sigemptyset( &mask );
     203//      sigaddset( &mask, sig );
     204
     205//      if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
     206//          abortf( "internal error, pthread_sigmask" );
     207//      } // if
     208// }
    208209
    209210static inline bool preemption_ready() {
     
    225226}
    226227
     228#ifdef __x86_64__
     229#define CFA_REG_IP REG_RIP
     230#else
     231#define CFA_REG_IP REG_EIP
     232#endif
     233
    227234void sigHandler_ctxSwitch( __CFA_SIGPARMS__ ) {
    228         LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "CtxSw IRH %10p running %10p @ %10p\n", this_processor, this_thread, (void *)(cxt->uc_mcontext.gregs[REG_RIP]) );
    229         LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[REG_RIP]); )
     235        LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); )
     236        verify( this_processor != systemProcessor );
    230237
    231238        if( preemption_ready() ) {
    232                 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Blocking thread %p on %p\n", this_thread, this_processor );
    233239                signal_unblock( SIGUSR1 );
    234240                BlockInternal( (thread_desc*)this_thread );
    235                 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Back\n\n");
    236241        }
    237242        else {
    238                 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Defering\n" );
    239243                defer_ctxSwitch();
    240                 signal_unblock( SIGUSR1 );
    241244        }
    242245}
    243246
    244247void sigHandler_alarm( __CFA_SIGPARMS__ ) {
    245         LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "\nAlarm IRH %10p running %10p @ %10p\n", this_processor, this_thread, (void *)(cxt->uc_mcontext.gregs[REG_RIP]) );
    246         LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[REG_RIP]); )
     248        LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); )
     249        verify( this_processor == systemProcessor );
    247250
    248251        if( try_lock( &systemProcessor->alarm_lock DEBUG_CTX2 ) ) {
    249252                tick_preemption();
     253                systemProcessor->pending_alarm = false;
    250254                unlock( &systemProcessor->alarm_lock );
    251255        }
     
    257261
    258262        if( preemption_ready() && this_processor->pending_preemption ) {
    259                 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm IRH : Blocking thread %p on %p\n", this_thread, this_processor );
     263
    260264                this_processor->pending_preemption = false;
    261265                BlockInternal( (thread_desc*)this_thread );
    262                 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm Switch IRH : Back\n\n");
    263266        }
    264267}
    265268
    266269static void preempt( processor * this ) {
    267         // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Processor : signalling %p\n", this );
    268 
    269270        if( this != systemProcessor ) {
    270271                pthread_kill( this->kernel_thread, SIGUSR1 );
     
    284285        act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler;
    285286        act.sa_flags = flags;
    286 
    287         // disabled during signal handler
    288         sigemptyset( &act.sa_mask );
    289         sigaddset( &act.sa_mask, sig );
    290287
    291288        if ( sigaction( sig, &act, NULL ) == -1 ) {
Note: See TracChangeset for help on using the changeset viewer.