source: rtems/cpukit/posix/src/psxtimercreate.c @ 21275b58

Last change on this file since 21275b58 was 21275b58, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 22, 2018 at 6:14:51 PM

score: Static Objects_Information initialization

Statically allocate the objects information together with the initial
set of objects either via <rtems/confdefs.h>. Provide default object
informations with zero objects via librtemscpu.a. This greatly
simplifies the workspace size estimate. RTEMS applications which do not
use the unlimited objects option are easier to debug since all objects
reside now in statically allocated objects of the right types.

Close #3621.

  • Property mode set to 100644
File size: 2.8 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/posix/sigset.h>
28#include <rtems/posix/timerimpl.h>
29#include <rtems/score/thread.h>
30#include <rtems/score/watchdogimpl.h>
31#include <rtems/seterr.h>
32#include <rtems/sysinit.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}
102
103static void _POSIX_Timer_Manager_initialization( void )
104{
105  _Objects_Initialize_information( &_POSIX_Timer_Information );
106}
107
108RTEMS_SYSINIT_ITEM(
109  _POSIX_Timer_Manager_initialization,
110  RTEMS_SYSINIT_POSIX_TIMER,
111  RTEMS_SYSINIT_ORDER_MIDDLE
112);
Note: See TracBrowser for help on using the repository browser.