source: rtems/cpukit/posix/src/alarm.c @ 0f01de2b

4.115
Last change on this file since 0f01de2b was 0f01de2b, checked in by Joel Sherrill <joel.sherrill@…>, on 12/10/13 at 15:08:16

alarm.c: Use _Assert() not assert()

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[65f6d3c]1/**
2 * @file
3 *
4 * @brief System Generates Signal for process after realtime seconds elapsed
[5cb175bb]5 * @ingroup POSIXAPI
[65f6d3c]6 */
7
[07d880f4]8/*
9 *  3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
[412dbff6]10 */
11
[967c1438]12/*  COPYRIGHT (c) 1989-2013.
[07d880f4]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
[8e36f29]17 *  http://www.rtems.com/license/LICENSE.
[07d880f4]18 */
19
[f42b726]20#if HAVE_CONFIG_H
21#include "config.h"
22#endif
[07d880f4]23
[5618c37a]24#include <unistd.h>
[07d880f4]25
[0c5317d]26#include <rtems/posix/pthreadimpl.h>
[f9340ed7]27#include <rtems/posix/psignalimpl.h>
[88c74ab]28#include <rtems/score/threaddispatch.h>
[f031df0e]29#include <rtems/score/todimpl.h>
[5618c37a]30#include <rtems/score/watchdogimpl.h>
[07d880f4]31
[64adc13]32/*
[b56c1a3]33 *  _POSIX_signals_Alarm_TSR
34 */
[596cbc56]35static void _POSIX_signals_Alarm_TSR(
[92f4671]36  Objects_Id      id __attribute__((unused)),
37  void           *argument __attribute__((unused))
[b56c1a3]38)
39{
[967c1438]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     */
[0f01de2b]54    _Assert(status == 0);
[967c1438]55  #endif
[b56c1a3]56}
57
[e2005af6]58static Watchdog_Control _POSIX_signals_Alarm_timer = WATCHDOG_INITIALIZER(
59  _POSIX_signals_Alarm_TSR,
60  0,
61  NULL
62);
63
[07d880f4]64unsigned int alarm(
65  unsigned int seconds
66)
67{
68  unsigned int      remaining = 0;
69  Watchdog_Control *the_timer;
[e2005af6]70  Watchdog_States   state;
[07d880f4]71
72  the_timer = &_POSIX_signals_Alarm_timer;
73
[a9cc1beb]74  _Thread_Disable_dispatch();
75
[e2005af6]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     */
[ff3c06a]83
[e2005af6]84    remaining = the_timer->initial -
85      ((the_timer->stop_time - the_timer->start_time) / TOD_TICKS_PER_SECOND);
[07d880f4]86  }
87
[8f6b7b51]88  if ( seconds )
89    _Watchdog_Insert_seconds( the_timer, seconds );
[07d880f4]90
[a9cc1beb]91  _Thread_Enable_dispatch();
92
[07d880f4]93  return remaining;
94}
Note: See TracBrowser for help on using the repository browser.