Timer problem

bridged with qdn.public.neutrino
Post Reply
David M. Cutler

Timer problem

Post by David M. Cutler » Tue Dec 23, 2003 3:39 pm

I am trying to start some timers to wake a thread. Right now I will be
happy to have just one of them going. what is happening right now, is I'm
using the TimerCreate() and TimerSettime() functions to set them up (this
one is supposed to be 5 seconds, but that does not matter now). I never
receive the events. I checked TimerInfo() and you can see that the
expirqtion time is all messed up, could someone please help. See code
below:

struct sigevent event;
SIGEV_SIGNAL_THREAD_INIT(&event, SIGALRM, NULL, TIMER_ANY_ADDRESS);
if((anyAddressTimer_new = TimerCreate(CLOCK_REALTIME, &event)) == -1){
printf("anyAddressTimer_new creation error:\n\t");
printf(sys_errlist[errno]);
printf("\n");
}
struct _itimer timerValue;
timerValue.nsec = 5000;
timerValue.interval_nsec = 5000;
if(TimerSettime(anyAddressTimer_new, 0, &timerValue, &oldTimerValue) == -1){
printf("anyAddressTimer_new settime error:\n\t");
printf(sys_errlist[errno]);
printf("\n");
}
struct _timer_info timerInfo;
if(TimerInfo(0, anyAddressTimer_new, 0, &timerInfo) == 0){
printf(
"anyAddressTimer timerInfo:\n"
"\tflags = %u\n"
"\ttid = %d\n"
"\tnotify = %d\n"
"\tclockid = %d\n"
"\toverruns = %u\n"
"\tevent.sigev_notify = %d\n"
"\tevent.sigev_signo = %d\n"
"\tevent.sigev_code = %d\n"
"\titime.nsec = %u\n"
"\titime.interval_nsec = %u\n"
"\totime.nsec = %u\n"
"\totime.interval_nsec = %u\n",
timerInfo.flags, timerInfo.tid, timerInfo.notify, timerInfo.clockid,
timerInfo.overruns, timerInfo.event.sigev_notify,
timerInfo.event.sigev_signo, timerInfo.event.sigev_code,
timerInfo.itime.nsec, timerInfo.itime.interval_nsec, timerInfo.otime.nsec,
timerInfo.otime.interval_nsec
);
}
else{
printf("anyAddressTimer_new info error:\n\t");
printf(sys_errlist[errno]);
printf("\n");
}
sigset_t signals;
sigemptyset(&signals);
siginfo_t info;
sigaddset(&signals, SIGALRM);
printf("(timerThread) Waiting for signal\n");
SignalWaitinfo(&signals, &info);

Here is the output:
Creating timers
anyAddressTimer timerInfo:
flags = 1
tid = 2
notify = 65539
clockid = 0
overruns = 0
event.sigev_notify = 65539
event.sigev_signo = 14
event.sigev_code = 1
itime.nsec = 3425683890
itime.ineterval_nsec = 693
otime.nsec = 5000
otime.inerval_nsec = 0
(timerThread) Waiting for signal

David M. Cutler

Mario Charest

Re: Timer problem

Post by Mario Charest » Tue Dec 23, 2003 8:21 pm

"David M. Cutler" <dcutler@nrtpos.com> wrote in message
news:bs9lug$4ff$1@inn.qnx.com...
I am trying to start some timers to wake a thread. Right now I will be
happy to have just one of them going. what is happening right now, is I'm
using the TimerCreate() and TimerSettime() functions to set them up (this
one is supposed to be 5 seconds, but that does not matter now). I never
receive the events. I checked TimerInfo() and you can see that the
expirqtion time is all messed up, could someone please help. See code
below:

struct sigevent event;
SIGEV_SIGNAL_THREAD_INIT(&event, SIGALRM, NULL, TIMER_ANY_ADDRESS);
Are you sure it's a thread and not process. I used SIGEV_SIGNAL_THREAD_INIT
and it worked for me
if((anyAddressTimer_new = TimerCreate(CLOCK_REALTIME, &event)) == -1){
printf("anyAddressTimer_new creation error:\n\t");
printf(sys_errlist[errno]);
printf("\n");
}
struct _itimer timerValue;

timerValue.nsec = 5000;
timerValue.interval_nsec = 5000;
5000 iss 5 us and not 5 seconds (value are nanosecondes).Depending on
machine speed the timer could have expired before you use actually wait for
it , and thus the SIGHANDLER may have already been called..

You should memset timerValue with 0 and you should use POSIX timer function
instead of non portable one. Look at timer_create.
That being said the function you are trying to use should work -)
if(TimerSettime(anyAddressTimer_new, 0, &timerValue, &oldTimerValue)
== -1){
printf("anyAddressTimer_new settime error:\n\t");
printf(sys_errlist[errno]);
printf("\n");
}
struct _timer_info timerInfo;
if(TimerInfo(0, anyAddressTimer_new, 0, &timerInfo) == 0){
printf(
"anyAddressTimer timerInfo:\n"
"\tflags = %u\n"
"\ttid = %d\n"
"\tnotify = %d\n"
"\tclockid = %d\n"
"\toverruns = %u\n"
"\tevent.sigev_notify = %d\n"
"\tevent.sigev_signo = %d\n"
"\tevent.sigev_code = %d\n"

"\titime.nsec = %u\n"
"\titime.interval_nsec = %u\n"
"\totime.nsec = %u\n"
"\totime.interval_nsec = %u\n",
These value are 64 bits but you specified a format that is integer (32 bit
on x86). Use %llu. If you had compile with warning enabled gcc would have
catch this.

Post Reply

Return to “qdn.public.neutrino”