source: rtems/cpukit/posix/src/alarm.c @ 8f6b7b5

4.104.11
Last change on this file since 8f6b7b5 was 8f6b7b5, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 11, 2009 at 10:37:38 PM

2009-10-11 Joel Sherrill <joel.sherrill@…>

  • posix/src/alarm.c: If 0 seconds do not insert timer.
  • rtems/src/regionextend.c: Eliminate warning. Use default else.
  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[07d880f4]1/*
2 *  3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
[412dbff6]3 */
4
5/*  COPYRIGHT (c) 1989-2007.
[07d880f4]6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
[8e36f29]10 *  http://www.rtems.com/license/LICENSE.
[07d880f4]11 *
12 *  $Id$
13 */
14
[f42b726]15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
[07d880f4]18
19#include <pthread.h>
20
21#include <rtems/system.h>
22#include <rtems/posix/pthread.h>
23#include <rtems/posix/psignal.h>
24
[b56c1a3]25Watchdog_Control _POSIX_signals_Alarm_timer;
26
27/*PAGE
28 *
29 *  _POSIX_signals_Alarm_TSR
30 */
[874297f3]31
[b56c1a3]32void _POSIX_signals_Alarm_TSR(
[92f4671]33  Objects_Id      id __attribute__((unused)),
34  void           *argument __attribute__((unused))
[b56c1a3]35)
36{
37  int status;
38
39  status = kill( getpid(), SIGALRM );
40  /* XXX can't print from an ISR, should this be fatal? */
41}
42
[07d880f4]43unsigned int alarm(
44  unsigned int seconds
45)
46{
47  unsigned int      remaining = 0;
48  Watchdog_Control *the_timer;
49
50  the_timer = &_POSIX_signals_Alarm_timer;
51
[b56c1a3]52  /*
53   *  Initialize the timer used to implement alarm().
54   */
55
56  if ( !the_timer->routine ) {
57    _Watchdog_Initialize( the_timer, _POSIX_signals_Alarm_TSR, 0, NULL );
58  } else {
[ff3c06a]59    Watchdog_States state;
60
61    state = _Watchdog_Remove( the_timer );
62    if ( (state == WATCHDOG_ACTIVE) || (state == WATCHDOG_REMOVE_IT) ) {
63      /*
64       *  The stop_time and start_time fields are snapshots of ticks since
65       *  boot.  Since alarm() is dealing in seconds, we must account for
66       *  this.
67       */
68
69      remaining = the_timer->initial -
70        ((the_timer->stop_time - the_timer->start_time) / TOD_TICKS_PER_SECOND);
[b56c1a3]71    }
[07d880f4]72  }
73
[8f6b7b5]74  if ( seconds )
75    _Watchdog_Insert_seconds( the_timer, seconds );
[07d880f4]76
77  return remaining;
78}
Note: See TracBrowser for help on using the repository browser.