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

4.115
Last change on this file since be1b8a7 was 4b48ece0, checked in by Sebastian Huber <sebastian.huber@…>, on 07/22/13 at 08:21:03

score: Create watchdog implementation header

Move implementation specific parts of watchdog.h and watchdog.inl into
new header file watchdogimpl.h. The watchdog.h contains now only the
application visible API.

  • 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.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#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/time.h>
32#include <rtems/posix/timerimpl.h>
33#include <rtems/score/watchdogimpl.h>
34
35int timer_create(
36  clockid_t        clock_id,
37  struct sigevent *evp,
38  timer_t         *timerid
39)
40{
41  POSIX_Timer_Control *ptimer;
42
43  if ( clock_id != CLOCK_REALTIME )
44    rtems_set_errno_and_return_minus_one( EINVAL );
45
46  if ( !timerid )
47    rtems_set_errno_and_return_minus_one( EINVAL );
48
49 /*
50  *  The data of the structure evp are checked in order to verify if they
51  *  are coherent.
52  */
53
54  if (evp != NULL) {
55    /* The structure has data */
56    if ( ( evp->sigev_notify != SIGEV_NONE ) &&
57         ( evp->sigev_notify != SIGEV_SIGNAL ) ) {
58       /* The value of the field sigev_notify is not valid */
59       rtems_set_errno_and_return_minus_one( EINVAL );
60     }
61
62     if ( !evp->sigev_signo )
63       rtems_set_errno_and_return_minus_one( EINVAL );
64
65     if ( !is_valid_signo(evp->sigev_signo) )
66       rtems_set_errno_and_return_minus_one( EINVAL );
67  }
68
69  _Thread_Disable_dispatch();         /* to prevent deletion */
70
71  /*
72   *  Allocate a timer
73   */
74  ptimer = _POSIX_Timer_Allocate();
75  if ( !ptimer ) {
76    _Objects_Put( &ptimer->Object );
77    rtems_set_errno_and_return_minus_one( EAGAIN );
78  }
79
80  /* The data of the created timer are stored to use them later */
81
82  ptimer->state     = POSIX_TIMER_STATE_CREATE_NEW;
83  ptimer->thread_id = _Thread_Executing->Object.id;
84
85  if ( evp != NULL ) {
86    ptimer->inf.sigev_notify = evp->sigev_notify;
87    ptimer->inf.sigev_signo  = evp->sigev_signo;
88    ptimer->inf.sigev_value  = evp->sigev_value;
89  }
90
91  ptimer->overrun  = 0;
92  ptimer->timer_data.it_value.tv_sec     = 0;
93  ptimer->timer_data.it_value.tv_nsec    = 0;
94  ptimer->timer_data.it_interval.tv_sec  = 0;
95  ptimer->timer_data.it_interval.tv_nsec = 0;
96
97  _Watchdog_Initialize( &ptimer->Timer, NULL, 0, NULL );
98  _Objects_Open_u32(&_POSIX_Timer_Information, &ptimer->Object, 0);
99
100  *timerid  = ptimer->Object.id;
101  _Objects_Put( &ptimer->Object );
102  return 0;
103}
Note: See TracBrowser for help on using the repository browser.