From e2005af632d0e38bcb9d47fe8fd7b82379d2e95f Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 22 Jul 2013 13:48:51 +0200 Subject: posix: Statically init _POSIX_signals_Alarm_timer --- cpukit/posix/src/alarm.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'cpukit/posix/src/alarm.c') diff --git a/cpukit/posix/src/alarm.c b/cpukit/posix/src/alarm.c index 190a7fbd5b..c671b9e161 100644 --- a/cpukit/posix/src/alarm.c +++ b/cpukit/posix/src/alarm.c @@ -41,35 +41,32 @@ static void _POSIX_signals_Alarm_TSR( /* XXX can't print from an ISR, should this be fatal? */ } +static Watchdog_Control _POSIX_signals_Alarm_timer = WATCHDOG_INITIALIZER( + _POSIX_signals_Alarm_TSR, + 0, + NULL +); + unsigned int alarm( unsigned int seconds ) { unsigned int remaining = 0; Watchdog_Control *the_timer; + Watchdog_States state; the_timer = &_POSIX_signals_Alarm_timer; - /* - * Initialize the timer used to implement alarm(). - */ - - if ( !the_timer->routine ) { - _Watchdog_Initialize( the_timer, _POSIX_signals_Alarm_TSR, 0, NULL ); - } else { - Watchdog_States state; - - state = _Watchdog_Remove( the_timer ); - if ( (state == WATCHDOG_ACTIVE) || (state == WATCHDOG_REMOVE_IT) ) { - /* - * The stop_time and start_time fields are snapshots of ticks since - * boot. Since alarm() is dealing in seconds, we must account for - * this. - */ + state = _Watchdog_Remove( the_timer ); + if ( (state == WATCHDOG_ACTIVE) || (state == WATCHDOG_REMOVE_IT) ) { + /* + * The stop_time and start_time fields are snapshots of ticks since + * boot. Since alarm() is dealing in seconds, we must account for + * this. + */ - remaining = the_timer->initial - - ((the_timer->stop_time - the_timer->start_time) / TOD_TICKS_PER_SECOND); - } + remaining = the_timer->initial - + ((the_timer->stop_time - the_timer->start_time) / TOD_TICKS_PER_SECOND); } if ( seconds ) -- cgit v1.2.3