source: rtems/cpukit/posix/src/timercreate.c @ dbb30e26

5
Last change on this file since dbb30e26 was 03b900d, checked in by Sebastian Huber <sebastian.huber@…>, on 02/18/16 at 07:36:26

score: Replace watchdog handler implementation

Use a red-black tree instead of delta chains.

Close #2344.
Update #2554.
Update #2555.
Close #2606.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Create a Per-Process Timer
5 * @ingroup POSIX_PRIV_TIMERS Timers
6 */
7
8/*
9 *  14.2.2 Create a Per-Process Timer, P1003.1b-1993, p. 264
10 *
11 *  COPYRIGHT (c) 1989-2007.
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#include <signal.h>
26
27#include <rtems/system.h>
28#include <rtems/seterr.h>
29#include <rtems/score/thread.h>
30#include <rtems/posix/sigset.h>
31#include <rtems/posix/timerimpl.h>
32#include <rtems/score/watchdogimpl.h>
33
34int timer_create(
35  clockid_t        clock_id,
36  struct sigevent *__restrict evp,
37  timer_t         *__restrict timerid
38)
39{
40  POSIX_Timer_Control *ptimer;
41
42  if ( clock_id != CLOCK_REALTIME )
43    rtems_set_errno_and_return_minus_one( EINVAL );
44
45  if ( !timerid )
46    rtems_set_errno_and_return_minus_one( EINVAL );
47
48 /*
49  *  The data of the structure evp are checked in order to verify if they
50  *  are coherent.
51  */
52
53  if (evp != NULL) {
54    /* The structure has data */
55    if ( ( evp->sigev_notify != SIGEV_NONE ) &&
56         ( evp->sigev_notify != SIGEV_SIGNAL ) ) {
57       /* The value of the field sigev_notify is not valid */
58       rtems_set_errno_and_return_minus_one( EINVAL );
59     }
60
61     if ( !evp->sigev_signo )
62       rtems_set_errno_and_return_minus_one( EINVAL );
63
64     if ( !is_valid_signo(evp->sigev_signo) )
65       rtems_set_errno_and_return_minus_one( EINVAL );
66  }
67
68  /*
69   *  Allocate a timer
70   */
71  ptimer = _POSIX_Timer_Allocate();
72  if ( !ptimer ) {
73    _Objects_Allocator_unlock();
74    rtems_set_errno_and_return_minus_one( EAGAIN );
75  }
76
77  /* The data of the created timer are stored to use them later */
78
79  ptimer->state     = POSIX_TIMER_STATE_CREATE_NEW;
80  ptimer->thread_id = _Thread_Get_executing()->Object.id;
81
82  if ( evp != NULL ) {
83    ptimer->inf.sigev_notify = evp->sigev_notify;
84    ptimer->inf.sigev_signo  = evp->sigev_signo;
85    ptimer->inf.sigev_value  = evp->sigev_value;
86  }
87
88  ptimer->overrun  = 0;
89  ptimer->timer_data.it_value.tv_sec     = 0;
90  ptimer->timer_data.it_value.tv_nsec    = 0;
91  ptimer->timer_data.it_interval.tv_sec  = 0;
92  ptimer->timer_data.it_interval.tv_nsec = 0;
93
94  _Watchdog_Preinitialize( &ptimer->Timer, _Per_CPU_Get_snapshot() );
95  _Watchdog_Initialize( &ptimer->Timer, _POSIX_Timer_TSR );
96  _Objects_Open_u32(&_POSIX_Timer_Information, &ptimer->Object, 0);
97
98  *timerid  = ptimer->Object.id;
99  _Objects_Allocator_unlock();
100  return 0;
101}
Note: See TracBrowser for help on using the repository browser.