summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/alarm.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/posix/src/alarm.c')
-rw-r--r--cpukit/posix/src/alarm.c59
1 files changed, 43 insertions, 16 deletions
diff --git a/cpukit/posix/src/alarm.c b/cpukit/posix/src/alarm.c
index 13c4c40202..dacd06adf0 100644
--- a/cpukit/posix/src/alarm.c
+++ b/cpukit/posix/src/alarm.c
@@ -22,6 +22,24 @@
#include <rtems/posix/pthread.h>
#include <rtems/posix/psignal.h>
+Watchdog_Control _POSIX_signals_Alarm_timer;
+
+/*PAGE
+ *
+ * _POSIX_signals_Alarm_TSR
+ */
+
+void _POSIX_signals_Alarm_TSR(
+ Objects_Id id,
+ void *argument
+)
+{
+ int status;
+
+ status = kill( getpid(), SIGALRM );
+ /* XXX can't print from an ISR, should this be fatal? */
+}
+
unsigned int alarm(
unsigned int seconds
)
@@ -31,22 +49,31 @@ unsigned int alarm(
the_timer = &_POSIX_signals_Alarm_timer;
- switch ( _Watchdog_Remove( the_timer ) ) {
- case WATCHDOG_INACTIVE:
- case WATCHDOG_BEING_INSERTED:
- break;
-
- case WATCHDOG_ACTIVE:
- case 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);
- break;
+ /*
+ * Initialize the timer used to implement alarm().
+ */
+
+ if ( !the_timer->routine ) {
+ _Watchdog_Initialize( the_timer, _POSIX_signals_Alarm_TSR, 0, NULL );
+ } else {
+ switch ( _Watchdog_Remove( the_timer ) ) {
+ case WATCHDOG_INACTIVE:
+ case WATCHDOG_BEING_INSERTED:
+ break;
+
+ case WATCHDOG_ACTIVE:
+ case 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);
+ break;
+ }
}
_Watchdog_Insert_seconds( the_timer, seconds );