source: rtems/cpukit/posix/src/timercreate.c @ 92f4671

4.104.115
Last change on this file since 92f4671 was ce19f1fa, checked in by Joel Sherrill <joel.sherrill@…>, on 01/23/08 at 22:57:43

2008-01-23 Joel Sherrill <joel.sherrill@…>

  • itron/include/rtems/itron/object.h, itron/src/cre_tsk.c, libblock/src/show_bdbuf.c, libmisc/capture/capture-cli.c, libmisc/capture/capture.c, libmisc/monitor/mon-manager.c, libmisc/stackchk/check.c, posix/src/condinit.c, posix/src/keycreate.c, posix/src/mqueuecreatesupp.c, posix/src/mqueuedeletesupp.c, posix/src/mqueuenametoid.c, posix/src/mqueueopen.c, posix/src/mqueueunlink.c, posix/src/mutexinit.c, posix/src/pbarrierinit.c, posix/src/prwlockinit.c, posix/src/pspininit.c, posix/src/pthreadcreate.c, posix/src/pthreadexit.c, posix/src/semaphorecreatesupp.c, posix/src/semaphorenametoid.c, posix/src/timercreate.c, rtems/src/barrierident.c, rtems/src/dpmemident.c, rtems/src/msgqident.c, rtems/src/partident.c, rtems/src/ratemonident.c, rtems/src/regionident.c, rtems/src/semident.c, rtems/src/taskident.c, rtems/src/timerident.c, sapi/src/extensionident.c, score/Makefile.am, score/include/rtems/score/object.h, score/inline/rtems/score/object.inl, score/src/apimutexallocate.c, score/src/objectextendinformation.c, score/src/objectgetnameasstring.c, score/src/objectmp.c, score/src/objectnametoid.c: Convert the Objects_Name type from a simple type to a union of an unsigned 32 bit integer and a pointer. This should help eliminate weird casts between u32 and pointers in various places. The APIs now have to explicitly call _u32 or _string versions of helper routines. This should also simplify things and eliminate the need for ugly casts in some cases.
  • score/src/objectclearname.c, score/src/objectcomparenameraw.c, score/src/objectcomparenamestring.c, score/src/objectcopynameraw.c, score/src/objectcopynamestring.c: Removed.
  • 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.