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

5
Last change on this file since f97536d was f97536d, checked in by Sebastian Huber <sebastian.huber@…>, on 10/16/15 at 06:21:48

basdefs.h: Add and use RTEMS_UNUSED

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief System Generates Signal for process after realtime seconds elapsed
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
10 */
11
12/*  COPYRIGHT (c) 1989-2013.
13 *  On-Line Applications Research Corporation (OAR).
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.org/license/LICENSE.
18 */
19
20#if HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <unistd.h>
25
26#include <rtems/posix/pthreadimpl.h>
27#include <rtems/posix/psignalimpl.h>
28#include <rtems/score/threaddispatch.h>
29#include <rtems/score/todimpl.h>
30#include <rtems/score/watchdogimpl.h>
31
32/*
33 *  _POSIX_signals_Alarm_TSR
34 */
35static void _POSIX_signals_Alarm_TSR(
36  Objects_Id      id RTEMS_UNUSED,
37  void           *argument RTEMS_UNUSED
38)
39{
40  #if defined(RTEMS_DEBUG)
41    int status;
42    #define KILL_STATUS status =
43  #else
44    #define KILL_STATUS (void)
45  #endif
46
47  KILL_STATUS kill( getpid(), SIGALRM );
48
49  #if defined(RTEMS_DEBUG)
50    /*
51     *  There is no reason to think this might fail but we should be
52     *  cautious.
53     */
54    _Assert(status == 0);
55  #endif
56}
57
58static Watchdog_Control _POSIX_signals_Alarm_timer = WATCHDOG_INITIALIZER(
59  _POSIX_signals_Alarm_TSR,
60  0,
61  NULL
62);
63
64unsigned int alarm(
65  unsigned int seconds
66)
67{
68  unsigned int      remaining = 0;
69  Watchdog_Control *the_timer;
70  Watchdog_States   state;
71
72  the_timer = &_POSIX_signals_Alarm_timer;
73
74  _Thread_Disable_dispatch();
75
76  state = _Watchdog_Remove_seconds( the_timer );
77  if ( state == WATCHDOG_ACTIVE ) {
78    /*
79     *  The stop_time and start_time fields are snapshots of ticks since
80     *  boot.  Since alarm() is dealing in seconds, we must account for
81     *  this.
82     */
83
84    remaining = the_timer->initial -
85      ((the_timer->stop_time - the_timer->start_time) / TOD_TICKS_PER_SECOND);
86  }
87
88  if ( seconds )
89    _Watchdog_Insert_seconds( the_timer, seconds );
90
91  _Thread_Enable_dispatch();
92
93  return remaining;
94}
Note: See TracBrowser for help on using the repository browser.