From a6cbc9b8690825aebde9694e9132230d57d53847 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 17 Dec 2007 16:01:42 +0000 Subject: 2007-12-17 Joel Sherrill * posix/Makefile.am, posix/preinstall.am, posix/include/rtems/posix/timer.h, score/src/objectget.c: Split POSIX Timer implementation into multiple files. Add obvious error checks for NULL parameters. Attempt to reduce include files. * posix/src/timercreate.c, posix/src/timerdelete.c, posix/src/timergetoverrun.c, posix/src/timergettime.c, posix/src/timerinserthelper.c, posix/src/timersettime.c, posix/src/timertsr.c: New files. * posix/src/ptimer1.c: Removed. --- cpukit/posix/src/timercreate.c | 97 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 cpukit/posix/src/timercreate.c (limited to 'cpukit/posix/src/timercreate.c') diff --git a/cpukit/posix/src/timercreate.c b/cpukit/posix/src/timercreate.c new file mode 100644 index 0000000000..90cb9b0f8b --- /dev/null +++ b/cpukit/posix/src/timercreate.c @@ -0,0 +1,97 @@ +/* + * 14.2.2 Create a Per-Process Timer, P1003.1b-1993, p. 264 + * + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +int timer_create( + clockid_t clock_id, + struct sigevent *evp, + timer_t *timerid +) +{ + POSIX_Timer_Control *ptimer; + + if ( clock_id != CLOCK_REALTIME ) + rtems_set_errno_and_return_minus_one( EINVAL ); + + if ( !timerid ) + rtems_set_errno_and_return_minus_one( EINVAL ); + + /* + * The data of the structure evp are checked in order to verify if they + * are coherent. + */ + + if (evp != NULL) { + /* The structure has data */ + if ( ( evp->sigev_notify != SIGEV_NONE ) && + ( evp->sigev_notify != SIGEV_SIGNAL ) ) { + /* The value of the field sigev_notify is not valid */ + rtems_set_errno_and_return_minus_one( EINVAL ); + } + + if ( !evp->sigev_signo ) + rtems_set_errno_and_return_minus_one( EINVAL ); + + if ( !is_valid_signo(evp->sigev_signo) ) + rtems_set_errno_and_return_minus_one( EINVAL ); + } + + _Thread_Disable_dispatch(); /* to prevent deletion */ + + /* + * Allocate a timer + */ + ptimer = _POSIX_Timer_Allocate(); + if ( !ptimer ) { + _Thread_Enable_dispatch(); + rtems_set_errno_and_return_minus_one( EAGAIN ); + } + + /* The data of the created timer are stored to use them later */ + + ptimer->state = POSIX_TIMER_STATE_CREATE_NEW; + ptimer->thread_id = _Thread_Executing->Object.id; + + if ( evp != NULL ) { + ptimer->inf.sigev_notify = evp->sigev_notify; + ptimer->inf.sigev_signo = evp->sigev_signo; + ptimer->inf.sigev_value = evp->sigev_value; + } + + ptimer->overrun = 0; + ptimer->timer_data.it_value.tv_sec = 0; + ptimer->timer_data.it_value.tv_nsec = 0; + ptimer->timer_data.it_interval.tv_sec = 0; + ptimer->timer_data.it_interval.tv_nsec = 0; + + _Watchdog_Initialize( &ptimer->Timer, NULL, 0, NULL ); + _Objects_Open(&_POSIX_Timer_Information, &ptimer->Object, (Objects_Name) 0); + + *timerid = ptimer->Object.id; + _Thread_Enable_dispatch(); + return 0; +} -- cgit v1.2.3