source: rtems/cpukit/posix/src/ualarm.c @ 860c34e

4.104.114.95
Last change on this file since 860c34e 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: 2.1 KB
Line 
1/*
2 *  3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
3 *
4 *  COPYRIGHT (c) 1989-2007.
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.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <pthread.h>
19/* #include <errno.h> */
20
21#include <rtems/system.h>
22#include <rtems/posix/pthread.h>
23#include <rtems/posix/psignal.h>
24#include <rtems/posix/time.h>
25
26Watchdog_Control _POSIX_signals_Ualarm_timer;
27
28/*PAGE
29 *
30 *  _POSIX_signals_Ualarm_TSR
31 */
32
33void _POSIX_signals_Ualarm_TSR(
34  Objects_Id      id,
35  void           *argument
36)
37{
38  int status;
39
40  status = kill( getpid(), SIGALRM );
41  /* XXX can't print from an ISR, should this be fatal? */
42}
43
44useconds_t ualarm(
45  useconds_t useconds,
46  useconds_t interval
47)
48{
49  useconds_t        remaining = 0;
50  Watchdog_Control *the_timer;
51  Watchdog_Interval ticks;
52  struct timespec   tp;
53
54  the_timer = &_POSIX_signals_Ualarm_timer;
55
56  /*
57   *  Initialize the timer used to implement alarm().
58   */
59
60  if ( !the_timer->routine ) {
61    _Watchdog_Initialize( the_timer, _POSIX_signals_Ualarm_TSR, 0, NULL );
62  } else {
63    switch ( _Watchdog_Remove( the_timer ) ) {
64      case WATCHDOG_INACTIVE:
65      case WATCHDOG_BEING_INSERTED:
66        break;
67
68      case WATCHDOG_ACTIVE:
69      case WATCHDOG_REMOVE_IT:
70        /*
71         *  The stop_time and start_time fields are snapshots of ticks since
72         *  boot.  Since alarm() is dealing in seconds, we must account for
73         *  this.
74         */
75
76        ticks = the_timer->initial;
77        ticks -= (the_timer->stop_time - the_timer->start_time);
78        /* remaining is now in ticks */
79
80        _Timespec_From_ticks( ticks, &tp );
81        remaining  = tp.tv_sec * TOD_MICROSECONDS_PER_SECOND;
82        remaining += tp.tv_nsec / 1000;
83        break;
84    }
85  }
86
87  tp.tv_sec = useconds / TOD_MICROSECONDS_PER_SECOND;
88  tp.tv_nsec = (useconds % TOD_MICROSECONDS_PER_SECOND) * 1000;
89  _Watchdog_Insert_ticks( the_timer, _Timespec_To_ticks( &tp ) );
90
91  return remaining;
92}
Note: See TracBrowser for help on using the repository browser.