source: rtems/cpukit/posix/src/alarm.c @ 967c1438

4.11
Last change on this file since 967c1438 was 967c1438, checked in by Joel Sherrill <joel.sherrill@…>, on Dec 9, 2013 at 9:36:38 PM

alarm.c: Per comment add debug code for kill() failing

This is highly unlikely and would indicate a serious bug
in the system or corruption. But it is better to be cautious.

  • 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.com/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 __attribute__((unused)),
37  void           *argument __attribute__((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( the_timer );
77  if ( (state == WATCHDOG_ACTIVE) || (state == WATCHDOG_REMOVE_IT) ) {
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.