Calling timer_settime(...) from within the notify function of a timer???
jchludzinski_at_gmail.com
Date: 06/24/05
- Next message: Andrei Voropaev: "libgcc_s.so.1 dependency"
- Previous message: krsyoung: "Re: Which project should I choose?"
- Next in thread: loic-dev_at_gmx.net: "Re: Calling timer_settime(...) from within the notify function of a timer???"
- Reply: loic-dev_at_gmx.net: "Re: Calling timer_settime(...) from within the notify function of a timer???"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 23 Jun 2005 21:57:37 -0700
I am calling timer_settime(...) from within the notify function of a
timer. The argument wait_time is the delta-t between real-world events
we are trying to emulate. Sometimes it (my code) get thru reading all
the events and scheduling the proper delta-t between them. And
sometimes it appears as if the timer is never reset (rescheduled) and
consequently no more events are read from the file and the process
halts. The expiring timer acts as a means/mechanism to iterate thru
the file of events.
Is there a problem in calling timer_settime(...) from with the notify
function? Am I not seeing something?
---John
static timer_t timer;
void start( void )
{
struct itimerspec itspec;
struct sigevent sigev;
memset( &sigev, 0, sizeof( struct sigevent ) );
sigev.sigev_value.sival_int = 0;
sigev.sigev_notify = SIGEV_THREAD;
sigev.sigev_notify_attributes = NULL;
sigev.sigev_notify_function = handler;
if ( timer_create( CLOCK_REALTIME, &sigev, &timer ) < 0 )
{
fprintf( stderr, "Function: %s, Line: %i, Error: %s\n",
__func__, __LINE__, strerror( errno ) );
exit( errno );
}
// Set the timer to expire after 1 sec...
itspec.it_value.tv_sec = 1;
itspec.it_value.tv_nsec = 0;
// ... as an one-shot timer.
itspec.it_interval.tv_sec = 0;
itspec.it_interval.tv_nsec = 0;
if ( timer_settime( timer_1, 0, &itspec, NULL ) < 0 )
{
fprintf( stderr, "Function: %s, Line: %i, Error: %s\n",
__func__, __LINE__, strerror ( errno ) );
exit( errno );
}
}
void reset_timer( float wait_time )
{
struct itimerspec itspec, otspec;
//if ( wait_time < 0.0 ) fatal_error( "wait_time < 0.0 in: %s\n",
__func__ );
//fprintf( stderr, "\nWait_time: %f\n\n", wait_time );
// Set the timer to expire after ??? ...
itspec.it_value.tv_sec = (int)wait_time;
itspec.it_value.tv_nsec = (int)( 1.0e9 * ( wait_time - floor(
wait_time ) ) ) + 10;
// ... as an one-shot timer.
itspec.it_interval.tv_sec = 0;
itspec.it_interval.tv_nsec = 0;
if ( timer_settime( timer_1, 0, &itspec, &otspec ) < 0 )
{
fprintf( stderr, "Function: %s, Line: %i, Error: %s\n",
__func__, __LINE__, strerror( errno ) );
exit( errno );
}
}
void handler( union sigval sigv )
{
pthread_mutex_lock( &m_scr );
printf( "\ntimer_nr = %02d pid = %d pthread_self = %ld\n",
sigv.sival_int, getpid(), pthread_self() );
if ( send_msg() == EXIT_FAILURE ) //send_msg eventually calls
reset_timer(...)
{
printf( "BEGINNING OF THE END: Function: %s Line: %i\n", __func__,
__LINE__ );
send_pdu_bytes( true );
clean_up();
}
pthread_mutex_unlock( &m_scr );
}
- Next message: Andrei Voropaev: "libgcc_s.so.1 dependency"
- Previous message: krsyoung: "Re: Which project should I choose?"
- Next in thread: loic-dev_at_gmx.net: "Re: Calling timer_settime(...) from within the notify function of a timer???"
- Reply: loic-dev_at_gmx.net: "Re: Calling timer_settime(...) from within the notify function of a timer???"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|