- Timestamp:
- Jul 4, 2008 11:37:58 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/posix/timer-posix.cpp
r9932 r10218 57 57 #endif 58 58 59 #define RT_TIMER_SIGNAL SIGUSR160 61 59 /******************************************************************************* 62 60 * Structures and Typedefs * … … 299 297 } 300 298 #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); 299 void 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 } 305 309 } 306 310 #endif /* !IPRT_WITH_POSIX_TIMERS */ … … 443 447 * Create a new timer. 444 448 */ 445 int rc , result;449 int rc; 446 450 PRTTIMER pTimer = (PRTTIMER)RTMemAlloc(sizeof(*pTimer)); 447 451 if (pTimer) 448 452 { 449 453 struct sigevent evt; 450 struct sigaction action, old;451 454 452 455 /* Initialize timer structure. */ … … 459 462 pTimer->iTick = 0; 460 463 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)); 466 471 if (RT_SUCCESS(rc)) 467 472 { 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; 481 475 } 482 476 RTMemFree(pTimer);
Note:
See TracChangeset
for help on using the changeset viewer.