I use timer_createto create a timer in Linux. Callback prototype:
static void TimerHandlerCB(int sig, siginfo_t *extra, void *cruft)
How can I pass user data so that I can get the same in the callback called after the timer expires.
Here is my sample code:
int RegisterTimer(iDiffInTime)
{
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = TimerHandlerCB;
if(sigaction(SIGRTMAX, &sa, NULL) < 0)
{
perror("sigaction");
return 1;
}
sigevent sigev;
timer_t timerid = 0;
memset(&sigev, 0, sizeof(sigev));
sigev.sigev_notify = SIGEV_SIGNAL;
sigev.sigev_signo = SIGRTMAX;
sigev.sigev_value.sival_ptr = &timerid;
timer_t timerid;
if (timer_create(CLOCK_REALTIME, &sigev, &timerid) == 0)
{
printf("Timer created\n");
struct itimerspec itval, oitval;
itval.it_value.tv_sec = iDiffInTime * 1000;
itval.it_value.tv_nsec = 0;
itval.it_interval.tv_sec = 0;
itval.it_interval.tv_nsec = 0;
Display_Handle hDisplay = ......
Buffer_Handle hBuf = .....
if (timer_settime(timerid, 0, &itval, &oitval) != 0)
{
perror("time_settime error!");
return 1;
}
}
else
{
perror("timer_create error!");
}
return 0
}
Where can I go hDisplayand hBufget them back to TimerHandlerCB?
source
share