 |
 |
Timer Implementation
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2004
Location: Brasil
Status:
Offline
|
|
I've a problem with a Solaris program implementation: My code uses a
timer procedure and when i try to execute date -a XXXX or rdate, my
aplication stops. I can't use ntp and need to set the machine time.
Here is my procedure. If you know how you can help me, please, do it.
static void handlerDelay() {
siglongjmp( env, 1 );
}
int XoPortUtilDelay( unsigned int milissec ) {
int houveTemporizacao = 0;
int segundos;
int microSeg;
struct itimerval tempoSleep;
void (*handlerAnterior)();
segundos = milissec / 1000;
microSeg = ( milissec % 1000 ) * 1000;
//!!!
if( microSeg < 50000 ){
microSeg = 50000;
}
//!!!
tempoSleep.it_value.tv_sec = segundos;
tempoSleep.it_value.tv_usec = microSeg;
tempoSleep.it_interval.tv_sec = 0;
tempoSleep.it_interval.tv_usec = 0;
handlerAnterior = signal( SIGALRM, handlerDelay );
if( handlerAnterior == SIG_ERR ){
return FALHA;
}
/* The first call to sigsetjmp show the point where the next
siglongjmp will return. Return always 0 at first time. When siglongjmp
is called (no signal handler), execution return to the call point to
sigsetjmp and the returned value are the specified as second argument
in siglongjmp. */
houveTemporizacao = sigsetjmp( env, 1 );
if( !houveTemporizacao ){
if( setitimer( ITIMER_REAL, &tempoSleep, NULL ) == -1 ){
return FALHA;
}
pause();
}
signal( SIGALRM, handlerAnterior );
return SUCESSO;
}//fim XoPorUtilDelay
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Sep 2003
Location: Pittsburgh, Pennsylvania
Status:
Offline
|
|
Originally posted by Ulisses:
I've a problem with a Solaris program implementation: My code uses a
timer procedure and when i try to execute date -a XXXX or rdate, my
aplication stops. I can't use ntp and need to set the machine time.
Here is my procedure. If you know how you can help me, please, do it.
static void handlerDelay() {
siglongjmp( env, 1 );
}
int XoPortUtilDelay( unsigned int milissec ) {
int houveTemporizacao = 0;
int segundos;
int microSeg;
struct itimerval tempoSleep;
void (*handlerAnterior)();
segundos = milissec / 1000;
microSeg = ( milissec % 1000 ) * 1000;
//!!!
if( microSeg < 50000 ){
microSeg = 50000;
}
//!!!
tempoSleep.it_value.tv_sec = segundos;
tempoSleep.it_value.tv_usec = microSeg;
tempoSleep.it_interval.tv_sec = 0;
tempoSleep.it_interval.tv_usec = 0;
handlerAnterior = signal( SIGALRM, handlerDelay );
if( handlerAnterior == SIG_ERR ){
return FALHA;
}
/* The first call to sigsetjmp show the point where the next
siglongjmp will return. Return always 0 at first time. When siglongjmp
is called (no signal handler), execution return to the call point to
sigsetjmp and the returned value are the specified as second argument
in siglongjmp. */
houveTemporizacao = sigsetjmp( env, 1 );
if( !houveTemporizacao ){
if( setitimer( ITIMER_REAL, &tempoSleep, NULL ) == -1 ){
return FALHA;
}
pause();
}
signal( SIGALRM, handlerAnterior );
return SUCESSO;
}//fim XoPorUtilDelay
Not understanding exactly what's happening only from the small bit of code hvae you tried stepping through the program with a debugger? I know 99% of my problems are either syntax errors, or using the wrong variable name. This could lead to strange errors. Check to make sure your pointers are initialized correctly also. I have had problems because the default value of a pointer was crazy, and that screwed up the whole prog. Best of luck.
nt
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|