source: rtems/cpukit/posix/src/timergettime.c @ 5cb175bb

4.115
Last change on this file since 5cb175bb was 5cb175bb, checked in by Joel Sherrill <joel.sherrill@…>, on 01/10/13 at 19:22:31

cpukit/posix: Doxygen group is POSIXAPI

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 * @file
3 *
4 * @brief Function Fetches State of POSIX Per-Process Timers
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  14.2.4 Per-Process Timers, P1003.1b-1993, p. 267
10 *
11 *  COPYRIGHT (c) 1989-2008.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.com/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <time.h>
24#include <errno.h>
25
26#include <rtems/system.h>
27#include <rtems/seterr.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/tod.h>
30#include <rtems/score/timespec.h>
31#include <rtems/posix/timer.h>
32
33/*
34 *          - When a timer is initialized, the value of the time in
35 *            that moment is stored.
36 *          - When this function is called, it returns the difference
37 *            between the current time and the initialization time.
38 */
39
40int timer_gettime(
41  timer_t            timerid,
42  struct itimerspec *value
43)
44{
45  POSIX_Timer_Control *ptimer;
46  Objects_Locations    location;
47  struct timespec      current_time;
48  Watchdog_Interval    left;
49
50  if ( !value )
51    rtems_set_errno_and_return_minus_one( EINVAL );
52
53  /* Reads the current time */
54  _TOD_Get( &current_time );
55
56  ptimer = _POSIX_Timer_Get( timerid, &location );
57  switch ( location ) {
58
59    case OBJECTS_LOCAL:
60
61      /* Calculates the time left before the timer finishes */
62
63      left =
64        (ptimer->Timer.start_time + ptimer->Timer.initial) - /* expire */
65        _Watchdog_Ticks_since_boot;                          /* now */
66
67      _Timespec_From_ticks( left, &value->it_value );
68
69      value->it_interval  = ptimer->timer_data.it_interval;
70
71      _Thread_Enable_dispatch();
72      return 0;
73
74#if defined(RTEMS_MULTIPROCESSING)
75    case OBJECTS_REMOTE:
76#endif
77    case OBJECTS_ERROR:
78      break;
79  }
80
81  rtems_set_errno_and_return_minus_one( EINVAL );
82}
Note: See TracBrowser for help on using the repository browser.