source: rtems/cpukit/posix/src/timergettime.c @ 127c20eb

5
Last change on this file since 127c20eb was 77e6eba7, checked in by Sebastian Huber <sebastian.huber@…>, on 03/07/16 at 15:01:57

score: Add and use _Objects_Get_local()

This simplifies the handling with local-only objects.

Update #2555.

  • Property mode set to 100644
File size: 1.7 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.org/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/posix/timerimpl.h>
27#include <rtems/score/todimpl.h>
28#include <rtems/score/watchdogimpl.h>
29#include <rtems/seterr.h>
30
31/*
32 *          - When a timer is initialized, the value of the time in
33 *            that moment is stored.
34 *          - When this function is called, it returns the difference
35 *            between the current time and the initialization time.
36 */
37
38int timer_gettime(
39  timer_t            timerid,
40  struct itimerspec *value
41)
42{
43  POSIX_Timer_Control *ptimer;
44  ISR_lock_Context     lock_context;
45  uint64_t             now;
46  uint32_t             remaining;
47
48  if ( !value )
49    rtems_set_errno_and_return_minus_one( EINVAL );
50
51  ptimer = _POSIX_Timer_Get( timerid, &lock_context );
52  if ( ptimer != NULL ) {
53    Per_CPU_Control *cpu;
54
55    cpu = _POSIX_Timer_Acquire_critical( ptimer, &lock_context );
56    now = cpu->Watchdog.ticks;
57
58    if ( now < ptimer->Timer.expire ) {
59      remaining = (uint32_t) ( ptimer->Timer.expire - now );
60    } else {
61      remaining = 0;
62    }
63
64    _Timespec_From_ticks( remaining, &value->it_value );
65    value->it_interval = ptimer->timer_data.it_interval;
66
67    _POSIX_Timer_Release( cpu, &lock_context );
68    return 0;
69  }
70
71  rtems_set_errno_and_return_minus_one( EINVAL );
72}
Note: See TracBrowser for help on using the repository browser.