source: rtems/cpukit/posix/src/timercreate.c @ 3bacb250

4.104.115
Last change on this file since 3bacb250 was 1de949a8, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/30/09 at 15:49:52

Whitespace removal.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 *  14.2.2 Create a Per-Process Timer, P1003.1b-1993, p. 264
3 *
4 *  COPYRIGHT (c) 1989-2007.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <time.h>
19#include <errno.h>
20#include <signal.h>
21
22#include <rtems/system.h>
23#include <rtems/seterr.h>
24#include <rtems/score/thread.h>
25#include <rtems/posix/psignal.h>
26#include <rtems/posix/time.h>
27#include <rtems/posix/timer.h>
28
29int timer_create(
30  clockid_t        clock_id,
31  struct sigevent *evp,
32  timer_t         *timerid
33)
34{
35  POSIX_Timer_Control *ptimer;
36
37  if ( clock_id != CLOCK_REALTIME )
38    rtems_set_errno_and_return_minus_one( EINVAL );
39
40  if ( !timerid )
41    rtems_set_errno_and_return_minus_one( EINVAL );
42
43 /*
44  *  The data of the structure evp are checked in order to verify if they
45  *  are coherent.
46  */
47
48  if (evp != NULL) {
49    /* The structure has data */
50    if ( ( evp->sigev_notify != SIGEV_NONE ) &&
51         ( evp->sigev_notify != SIGEV_SIGNAL ) ) {
52       /* The value of the field sigev_notify is not valid */
53       rtems_set_errno_and_return_minus_one( EINVAL );
54     }
55
56     if ( !evp->sigev_signo )
57       rtems_set_errno_and_return_minus_one( EINVAL );
58
59     if ( !is_valid_signo(evp->sigev_signo) )
60       rtems_set_errno_and_return_minus_one( EINVAL );
61  }
62
63  _Thread_Disable_dispatch();         /* to prevent deletion */
64
65  /*
66   *  Allocate a timer
67   */
68  ptimer = _POSIX_Timer_Allocate();
69  if ( !ptimer ) {
70    _Thread_Enable_dispatch();
71    rtems_set_errno_and_return_minus_one( EAGAIN );
72  }
73
74  /* The data of the created timer are stored to use them later */
75
76  ptimer->state     = POSIX_TIMER_STATE_CREATE_NEW;
77  ptimer->thread_id = _Thread_Executing->Object.id;
78
79  if ( evp != NULL ) {
80    ptimer->inf.sigev_notify = evp->sigev_notify;
81    ptimer->inf.sigev_signo  = evp->sigev_signo;
82    ptimer->inf.sigev_value  = evp->sigev_value;
83  }
84
85  ptimer->overrun  = 0;
86  ptimer->timer_data.it_value.tv_sec     = 0;
87  ptimer->timer_data.it_value.tv_nsec    = 0;
88  ptimer->timer_data.it_interval.tv_sec  = 0;
89  ptimer->timer_data.it_interval.tv_nsec = 0;
90
91  _Watchdog_Initialize( &ptimer->Timer, NULL, 0, NULL );
92  _Objects_Open_u32(&_POSIX_Timer_Information, &ptimer->Object, 0);
93
94  *timerid  = ptimer->Object.id;
95  _Thread_Enable_dispatch();
96  return 0;
97}
Note: See TracBrowser for help on using the repository browser.