source: rtems/c/src/exec/posix/src/alarm.c @ df976833

4.104.114.84.95
Last change on this file since df976833 was df976833, checked in by Joel Sherrill <joel.sherrill@…>, on 07/07/00 at 19:31:30

Fixed problem reported by Victor V. Vengerov <Victor.Vengerov@…>
where alarm() did not correctly account for the watchdog start_time
and stop_time fields being based on ticks not seconds. This resulted
in alarm() returning a bogus number of seconds remaining.

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[07d880f4]1/*
2 *  3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
3 *
[08311cc3]4 *  COPYRIGHT (c) 1989-1999.
[07d880f4]5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.OARcorp.com/rtems/license.html.
10 *
11 *  $Id$
12 */
13
14
15#include <pthread.h>
16#include <errno.h>
17
18#include <rtems/system.h>
19#include <rtems/posix/pthread.h>
20#include <rtems/posix/psignal.h>
21
22unsigned int alarm(
23  unsigned int seconds
24)
25{
26  unsigned int      remaining = 0;
27  Watchdog_Control *the_timer;
28
29  the_timer = &_POSIX_signals_Alarm_timer;
30
31  switch ( _Watchdog_Remove( the_timer ) ) {
32    case WATCHDOG_INACTIVE:
33    case WATCHDOG_BEING_INSERTED:
34      break;
35
36    case WATCHDOG_ACTIVE:
37    case WATCHDOG_REMOVE_IT:
[df976833]38      /*
39       *  The stop_time and start_time fields are snapshots of ticks since
40       *  boot.  Since alarm() is dealing in seconds, we must account for
41       *  this.
42       */
43
[07d880f4]44      remaining = the_timer->initial -
[df976833]45       ((the_timer->stop_time - the_timer->start_time) / _TOD_Ticks_per_second);
[07d880f4]46      break;
47  }
48
49  _Watchdog_Insert_seconds( the_timer, seconds );
50
51  return remaining;
52}
53
Note: See TracBrowser for help on using the repository browser.