source: rtems/cpukit/posix/src/alarm.c @ 412dbff6

4.104.114.84.95
Last change on this file since 412dbff6 was 412dbff6, checked in by Joel Sherrill <joel.sherrill@…>, on 04/05/07 at 21:17:27

2007-04-05 Joel Sherrill <joel@…>

  • posix/Makefile.am, posix/include/rtems/posix/time.h, posix/src/adjtime.c, posix/src/alarm.c, posix/src/clockgetres.c, posix/src/condtimedwait.c, posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c, posix/src/mutextimedlock.c, posix/src/nanosleep.c, posix/src/posixtimespecabsolutetimeout.c, posix/src/pthread.c, posix/src/pthreadcreate.c, posix/src/pthreadsetschedparam.c, posix/src/ptimer1.c, posix/src/sched.c, posix/src/semtimedwait.c, posix/src/sigtimedwait.c, posix/src/ualarm.c, rtems/src/clocktodtoseconds.c, score/Makefile.am, score/preinstall.am, score/include/rtems/score/tod.h, score/inline/rtems/score/tod.inl, score/src/coretod.c, score/src/coretodget.c, score/src/coretodgetuptime.c, score/src/coretodset.c, score/src/coretodtickle.c: Provide timespec manipulation routines in the SuperCore?. Use them everywhere possible. This lead to significant cleanup in the API routines and eliminated some of the same code from the POSIX API. At this point, the SuperCore? keeps time in POSIX timespec format properly from 1970. You just cannot set it before 1988 in keeping with RTEMS traditional behavior.
  • score/include/rtems/score/timespec.h, score/src/timespecaddto.c, score/src/timespecfromticks.c, score/src/timespecisvalid.c, score/src/timespeclessthan.c, score/src/timespecsubtract.c, score/src/timespectoticks.c: New files.
  • posix/src/posixintervaltotimespec.c, posix/src/posixtimespecsubtract.c, posix/src/posixtimespectointerval.c: Removed.
  • Property mode set to 100644
File size: 1.7 KB
Line 
1/*
2 *  3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
3 */
4
5/*  COPYRIGHT (c) 1989-2007.
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
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <pthread.h>
20
21#include <rtems/system.h>
22#include <rtems/posix/pthread.h>
23#include <rtems/posix/psignal.h>
24
25Watchdog_Control _POSIX_signals_Alarm_timer;
26
27/*PAGE
28 *
29 *  _POSIX_signals_Alarm_TSR
30 */
31
32void _POSIX_signals_Alarm_TSR(
33  Objects_Id      id,
34  void           *argument
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
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
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 {
59    switch ( _Watchdog_Remove( the_timer ) ) {
60      case WATCHDOG_INACTIVE:
61      case WATCHDOG_BEING_INSERTED:
62        break;
63
64      case WATCHDOG_ACTIVE:
65      case WATCHDOG_REMOVE_IT:
66        /*
67         *  The stop_time and start_time fields are snapshots of ticks since
68         *  boot.  Since alarm() is dealing in seconds, we must account for
69         *  this.
70         */
71
72        remaining = the_timer->initial -
73         ((the_timer->stop_time - the_timer->start_time) /
74           TOD_TICKS_PER_SECOND);
75        break;
76    }
77  }
78
79  _Watchdog_Insert_seconds( the_timer, seconds );
80
81  return remaining;
82}
Note: See TracBrowser for help on using the repository browser.