Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Timer Implementation

Timer Implementation
Thread Tools
Fresh-Faced Recruit
Join Date: Apr 2004
Location: Brasil
Status: Offline
Reply With Quote
Apr 6, 2004, 12:17 PM
 
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
Reply With Quote
Apr 6, 2004, 10:40 PM
 
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
Apple iBook, B&W, Quadra 660, PowerMac 6100
Sun Netra T1, Ultra 1, Javastation
http://natetobik.mine.nu:81
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:23 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2