source: rtems/cpukit/posix/src/alarm.c @ a0e6c73

4.115
Last change on this file since a0e6c73 was f9340ed7, checked in by Sebastian Huber <sebastian.huber@…>, on 12/03/12 at 10:35:43

posix: Add and use <rtems/posix/psignalimpl.h>

This file contains the parts of <rtems/posix/psignal.h> that are only
necessary for the POSIX API implementation.

  • Property mode set to 100644
File size: 1.6 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
13#if HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include <pthread.h>
18
19#include <rtems/system.h>
20#include <rtems/posix/pthread.h>
21#include <rtems/posix/psignalimpl.h>
22
23/*
24 *  _POSIX_signals_Alarm_TSR
25 */
26
27static void _POSIX_signals_Alarm_TSR(
28  Objects_Id      id __attribute__((unused)),
29  void           *argument __attribute__((unused))
30)
31{
32  kill( getpid(), SIGALRM );
33  /* XXX can't print from an ISR, should this be fatal? */
34}
35
36unsigned int alarm(
37  unsigned int seconds
38)
39{
40  unsigned int      remaining = 0;
41  Watchdog_Control *the_timer;
42
43  the_timer = &_POSIX_signals_Alarm_timer;
44
45  /*
46   *  Initialize the timer used to implement alarm().
47   */
48
49  if ( !the_timer->routine ) {
50    _Watchdog_Initialize( the_timer, _POSIX_signals_Alarm_TSR, 0, NULL );
51  } else {
52    Watchdog_States state;
53
54    state = _Watchdog_Remove( the_timer );
55    if ( (state == WATCHDOG_ACTIVE) || (state == WATCHDOG_REMOVE_IT) ) {
56      /*
57       *  The stop_time and start_time fields are snapshots of ticks since
58       *  boot.  Since alarm() is dealing in seconds, we must account for
59       *  this.
60       */
61
62      remaining = the_timer->initial -
63        ((the_timer->stop_time - the_timer->start_time) / TOD_TICKS_PER_SECOND);
64    }
65  }
66
67  if ( seconds )
68    _Watchdog_Insert_seconds( the_timer, seconds );
69
70  return remaining;
71}
Note: See TracBrowser for help on using the repository browser.