VirtualBox

Changeset 10218

Show
Ignore:
Timestamp:
07/04/08 13:37:58 (2 months ago)
Author:
vboxsync
Message:

POSIX timers, take two. No signals at all.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/VBox/Runtime/r3/posix/timer-posix.cpp

    r9932 r10218  
    5757#endif 
    5858 
    59 #define RT_TIMER_SIGNAL SIGUSR1 
    60  
    6159/******************************************************************************* 
    6260*   Structures and Typedefs                                                    * 
     
    299297} 
    300298#else /* !IPRT_WITH_POSIX_TIMERS */ 
    301 void rtSignalCallback(int sig, siginfo_t *sip, void *ucp) 
    302 
    303     PRTTIMER pTimer = (PRTTIMER)sip->_sifields._timer.si_sigval.sival_ptr; 
    304     pTimer->pfnTimer(pTimer, pTimer->pvUser, ++pTimer->iTick); 
     299void rttimerCallback(union sigval SigVal) 
     300
     301    PRTTIMER pTimer = (PRTTIMER)SigVal.sival_ptr; 
     302    /* Is the timer being destoyed/suspended at this very moment? */ 
     303    if (RT_LIKELY(pTimer->u32Magic == RTTIMER_MAGIC 
     304                  && !pTimer->fSuspended 
     305                  && !pTimer->fDestroyed)) 
     306    { 
     307        pTimer->pfnTimer(pTimer, pTimer->pvUser, ++pTimer->iTick); 
     308    } 
    305309} 
    306310#endif /* !IPRT_WITH_POSIX_TIMERS */ 
     
    443447     * Create a new timer. 
    444448     */ 
    445     int rc, result
     449    int rc
    446450    PRTTIMER pTimer = (PRTTIMER)RTMemAlloc(sizeof(*pTimer)); 
    447451    if (pTimer) 
    448452    { 
    449453        struct sigevent  evt; 
    450         struct sigaction action, old; 
    451454 
    452455        /* Initialize timer structure. */ 
     
    459462        pTimer->iTick           = 0; 
    460463 
    461         /* Set up the signal handler. */ 
    462         sigemptyset(&action.sa_mask); 
    463         action.sa_sigaction = rtSignalCallback; 
    464         action.sa_flags     = SA_SIGINFO | SA_RESTART; 
    465         rc = RTErrConvertFromErrno(sigaction(RT_TIMER_SIGNAL, &action, &old)); 
     464        /* Ask to call rttimerCallback in a separate thread context upon timer expiration. */ 
     465        memset(&evt, 0, sizeof(evt)); 
     466        evt.sigev_notify = SIGEV_THREAD; 
     467        evt.sigev_value.sival_ptr = pTimer; 
     468        evt.sigev_notify_function = rttimerCallback; 
     469 
     470        rc = RTErrConvertFromErrno(timer_create(CLOCK_REALTIME, &evt, &pTimer->timer)); 
    466471        if (RT_SUCCESS(rc)) 
    467472        { 
    468  
    469             /* Ask to deliver RT_TIMER_SIGNAL upon timer expiration. */ 
    470             evt.sigev_notify = SIGEV_SIGNAL; 
    471             evt.sigev_signo  = RT_TIMER_SIGNAL; 
    472             evt.sigev_value.sival_ptr = pTimer; /* sigev_value gets copied to siginfo. */ 
    473  
    474             rc = RTErrConvertFromErrno(timer_create(CLOCK_REALTIME, &evt, &pTimer->timer)); 
    475             if (RT_SUCCESS(rc)) 
    476             { 
    477                 *ppTimer = pTimer; 
    478                 return VINF_SUCCESS; 
    479             } 
    480             sigaction(RT_TIMER_SIGNAL, &old, NULL); 
     473            *ppTimer = pTimer; 
     474            return VINF_SUCCESS; 
    481475        } 
    482476        RTMemFree(pTimer); 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy