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

4.115
Last change on this file since a0e6c73 was a0e6c73, checked in by Mathew Kallada <matkallada@…>, on 12/14/12 at 01:51:15

posix: Doxygen enhancement task #4

http://www.google-melange.com/gci/task/view/google/gci2012/7955219

  • Property mode set to 100644
File size: 2.5 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/timer.h>
33
34int timer_create(
35  clockid_t        clock_id,
36  struct sigevent *evp,
37  timer_t         *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  _Thread_Disable_dispatch();         /* to prevent deletion */
69
70  /*
71   *  Allocate a timer
72   */
73  ptimer = _POSIX_Timer_Allocate();
74  if ( !ptimer ) {
75    _Thread_Enable_dispatch();
76    rtems_set_errno_and_return_minus_one( EAGAIN );
77  }
78
79  /* The data of the created timer are stored to use them later */
80
81  ptimer->state     = POSIX_TIMER_STATE_CREATE_NEW;
82  ptimer->thread_id = _Thread_Executing->Object.id;
83
84  if ( evp != NULL ) {
85    ptimer->inf.sigev_notify = evp->sigev_notify;
86    ptimer->inf.sigev_signo  = evp->sigev_signo;
87    ptimer->inf.sigev_value  = evp->sigev_value;
88  }
89
90  ptimer->overrun  = 0;
91  ptimer->timer_data.it_value.tv_sec     = 0;
92  ptimer->timer_data.it_value.tv_nsec    = 0;
93  ptimer->timer_data.it_interval.tv_sec  = 0;
94  ptimer->timer_data.it_interval.tv_nsec = 0;
95
96  _Watchdog_Initialize( &ptimer->Timer, NULL, 0, NULL );
97  _Objects_Open_u32(&_POSIX_Timer_Information, &ptimer->Object, 0);
98
99  *timerid  = ptimer->Object.id;
100  _Thread_Enable_dispatch();
101  return 0;
102}
Note: See TracBrowser for help on using the repository browser.