summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/timersettime.c
diff options
context:
space:
mode:
authorJennifer Averett <Jennifer.Averett@OARcorp.com>2008-01-18 16:31:57 +0000
committerJennifer Averett <Jennifer.Averett@OARcorp.com>2008-01-18 16:31:57 +0000
commitc3925dbe923bf0944235bc2c4556955f35b0dc91 (patch)
treecebd73d709e9f2c152f42d14362923dded35f0ef /cpukit/posix/src/timersettime.c
parent2008-01-18 David Erickson <David.Erickson@drdc-rddc.gc.ca> (diff)
downloadrtems-c3925dbe923bf0944235bc2c4556955f35b0dc91.tar.bz2
2008-01-18 Jennifer Averett <jennifer.averett@OARcorp.com>
* posix/include/rtems/posix/timer.h, posix/src/cleanuppop.c, posix/src/cleanuppush.c, posix/src/mqueueclose.c, posix/src/timergettime.c, posix/src/timersettime.c, score/include/rtems/score/timespec.h:
Diffstat (limited to 'cpukit/posix/src/timersettime.c')
-rw-r--r--cpukit/posix/src/timersettime.c100
1 files changed, 37 insertions, 63 deletions
diff --git a/cpukit/posix/src/timersettime.c b/cpukit/posix/src/timersettime.c
index c1cea14484..05260360e7 100644
--- a/cpukit/posix/src/timersettime.c
+++ b/cpukit/posix/src/timersettime.c
@@ -1,7 +1,7 @@
/*
* 14.2.4 Per-Process Timers, P1003.1b-1993, p. 267
*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -36,6 +36,7 @@ int timer_settime(
POSIX_Timer_Control *ptimer;
Objects_Locations location;
boolean activated;
+ struct itimerspec normalize;
if ( !value )
rtems_set_errno_and_return_minus_one( EINVAL );
@@ -47,12 +48,19 @@ int timer_settime(
rtems_set_errno_and_return_minus_one( EINVAL );
}
- /* XXX check for seconds in the past */
-
if ( flags != TIMER_ABSTIME && flags != POSIX_TIMER_RELATIVE ) {
rtems_set_errno_and_return_minus_one( EINVAL );
}
+ normalize = *value;
+
+ /* Convert absolute to relative time */
+ if (flags == TIMER_ABSTIME) {
+ /* Check for seconds in the past */
+ if ( _Timespec_Greater_than( &normalize, &_TOD_Now ) )
+ rtems_set_errno_and_return_minus_one( EINVAL );
+ _Timespec_Subtract( &_TOD_Now, &normalize.it_value, &normalize.it_value);
+ }
/* If the function reaches this point, then it will be necessary to do
* something with the structure of times of the timer: to stop, start
* or start it again
@@ -63,14 +71,14 @@ int timer_settime(
case OBJECTS_LOCAL:
/* First, it verifies if the timer must be stopped */
- if ( value->it_value.tv_sec == 0 && value->it_value.tv_nsec == 0 ) {
+ if ( normalize.it_value.tv_sec == 0 && normalize.it_value.tv_nsec == 0 ) {
/* Stop the timer */
(void) _Watchdog_Remove( &ptimer->Timer );
/* The old data of the timer are returned */
if ( ovalue )
*ovalue = ptimer->timer_data;
/* The new data are set */
- ptimer->timer_data = *value;
+ ptimer->timer_data = normalize;
/* Indicates that the timer is created and stopped */
ptimer->state = POSIX_TIMER_STATE_CREATE_STOP;
/* Returns with success */
@@ -78,64 +86,30 @@ int timer_settime(
return 0;
}
- /* absolute or relative? */
- switch (flags) {
- case TIMER_ABSTIME:
-
- /* The fire time is absolute: use "rtems_time_fire_when" */
- /* First, it converts from struct itimerspec to rtems_time_of_day */
-
- _Watchdog_Initialize(
- &ptimer->Timer, _POSIX_Timer_TSR, ptimer->Object.id, ptimer );
-
- _Watchdog_Insert_seconds(
- &ptimer->Timer,
- value->it_value.tv_sec - _TOD_Seconds_since_epoch
- );
-
- /* Returns the old ones in "ovalue" */
- if ( ovalue )
- *ovalue = ptimer->timer_data;
- ptimer->timer_data = *value;
-
- /* Indicate that the time is running */
- ptimer->state = POSIX_TIMER_STATE_CREATE_RUN;
-
- /* Stores the time in which the timer was started again */
- _TOD_Get( &ptimer->time );
- _Thread_Enable_dispatch();
- return 0;
- break;
-
- /* The fire time is relative: use "rtems_time_fire_after" */
- case POSIX_TIMER_RELATIVE:
- /* First, convert from seconds and nanoseconds to ticks */
- ptimer->ticks = _Timespec_To_ticks( &value->it_value );
-
- activated = _POSIX_Timer_Insert_helper(
- &ptimer->Timer,
- ptimer->ticks,
- ptimer->Object.id,
- _POSIX_Timer_TSR,
- ptimer
- );
- if ( !activated )
- return 0;
-
- /* The timer has been started and is running */
- /* return the old ones in "ovalue" */
- if ( ovalue )
- *ovalue = ptimer->timer_data;
- ptimer->timer_data = *value;
-
- /* Indicate that the time is running */
- ptimer->state = POSIX_TIMER_STATE_CREATE_RUN;
- _TOD_Get( &ptimer->time );
- _Thread_Enable_dispatch();
- return 0;
- }
- _Thread_Enable_dispatch();
- break;
+ /* Convert from seconds and nanoseconds to ticks */
+ ptimer->ticks = _Timespec_To_ticks( &normalize.it_value );
+
+ activated = _POSIX_Timer_Insert_helper(
+ &ptimer->Timer,
+ ptimer->ticks,
+ ptimer->Object.id,
+ _POSIX_Timer_TSR,
+ ptimer
+ );
+ if ( !activated )
+ return 0;
+
+ /* The timer has been started and is running */
+ /* return the old ones in "ovalue" */
+ if ( ovalue )
+ *ovalue = ptimer->timer_data;
+ ptimer->timer_data = normalize;
+
+ /* Indicate that the time is running */
+ ptimer->state = POSIX_TIMER_STATE_CREATE_RUN;
+ _TOD_Get( &ptimer->time );
+ _Thread_Enable_dispatch();
+ return 0;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE: