summaryrefslogtreecommitdiffstats
path: root/cpukit/posix
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
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')
-rw-r--r--cpukit/posix/include/rtems/posix/timer.h4
-rw-r--r--cpukit/posix/src/cleanuppop.c16
-rw-r--r--cpukit/posix/src/cleanuppush.c27
-rw-r--r--cpukit/posix/src/mqueueclose.c23
-rw-r--r--cpukit/posix/src/timergettime.c13
-rw-r--r--cpukit/posix/src/timersettime.c100
6 files changed, 83 insertions, 100 deletions
diff --git a/cpukit/posix/include/rtems/posix/timer.h b/cpukit/posix/include/rtems/posix/timer.h
index e03a835ad1..ba9d5368db 100644
--- a/cpukit/posix/include/rtems/posix/timer.h
+++ b/cpukit/posix/include/rtems/posix/timer.h
@@ -3,7 +3,7 @@
*/
/*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -56,7 +56,7 @@ typedef struct {
struct itimerspec timer_data; /* Timing data of the timer */
uint32_t ticks; /* Number of ticks of the initialization */
uint32_t overrun; /* Number of expirations of the timer */
- struct timespec time; /* Time in which the timer was started */
+ struct timespec time; /* Time at which the timer was started */
} POSIX_Timer_Control;
/*
diff --git a/cpukit/posix/src/cleanuppop.c b/cpukit/posix/src/cleanuppop.c
index f919228801..cc327fa33d 100644
--- a/cpukit/posix/src/cleanuppop.c
+++ b/cpukit/posix/src/cleanuppop.c
@@ -1,5 +1,5 @@
/*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -44,8 +44,18 @@ void pthread_cleanup_pop(
handler_stack = &thread_support->Cancellation_Handlers;
+ /*
+ * We need interrupts disabled to safely check the chain and pull
+ * the last element off. But we also need dispatching disabled to
+ * ensure that we do not get prempted and deleted while we are holding
+ * memory that needs to be freed.
+ */
+
+ _Thread_Disable_dispatch();
_ISR_Disable( level );
+
if ( _Chain_Is_empty( handler_stack ) ) {
+ _Thread_Enable_dispatch();
_ISR_Enable( level );
return;
}
@@ -58,8 +68,8 @@ void pthread_cleanup_pop(
tmp_handler = *handler;
- _Thread_Disable_dispatch();
- _Workspace_Free( handler );
+ _Workspace_Free( handler );
+
_Thread_Enable_dispatch();
if ( execute )
diff --git a/cpukit/posix/src/cleanuppush.c b/cpukit/posix/src/cleanuppush.c
index 964b3c4933..557b3e2d62 100644
--- a/cpukit/posix/src/cleanuppush.c
+++ b/cpukit/posix/src/cleanuppush.c
@@ -1,5 +1,5 @@
/*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -39,25 +39,26 @@ void pthread_cleanup_push(
Chain_Control *handler_stack;
POSIX_API_Control *thread_support;
+ /*
+ * The POSIX standard does not address what to do when the routine
+ * is NULL. It also does not address what happens when we cannot
+ * allocate memory or anything else bad happens.
+ */
if ( !routine )
- return; /* XXX what to do really? */
+ return;
_Thread_Disable_dispatch();
handler = _Workspace_Allocate( sizeof( POSIX_Cancel_Handler_control ) );
- if ( !handler ) {
- _Thread_Enable_dispatch();
- return; /* XXX what to do really? */
- }
-
- thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
+ if ( handler ) {
+ thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
- handler_stack = &thread_support->Cancellation_Handlers;
+ handler_stack = &thread_support->Cancellation_Handlers;
- handler->routine = routine;
- handler->arg = arg;
-
- _Chain_Append( handler_stack, &handler->Node );
+ handler->routine = routine;
+ handler->arg = arg;
+ _Chain_Append( handler_stack, &handler->Node );
+ }
_Thread_Enable_dispatch();
}
diff --git a/cpukit/posix/src/mqueueclose.c b/cpukit/posix/src/mqueueclose.c
index e95118b2e0..35b4dc3ec1 100644
--- a/cpukit/posix/src/mqueueclose.c
+++ b/cpukit/posix/src/mqueueclose.c
@@ -11,7 +11,7 @@
* This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
* time.
*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -53,10 +53,9 @@ int mq_close(
Objects_Locations location;
the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
- switch ( location ) {
-
- case OBJECTS_LOCAL:
- /*
+ if ( location == OBJECTS_LOCAL ) {
+ /* OBJECTS_LOCAL:
+ *
* First update the actual message queue to reflect this descriptor
* being disassociated. This may result in the queue being really
* deleted.
@@ -76,13 +75,11 @@ int mq_close(
_Thread_Enable_dispatch();
return 0;
+ }
-#if defined(RTEMS_MULTIPROCESSING)
- case OBJECTS_REMOTE:
-#endif
- case OBJECTS_ERROR:
- break;
- }
-
- rtems_set_errno_and_return_minus_one( EBADF );
+ /*
+ * OBJECTS_REMOTE:
+ * OBJECTS_ERROR:
+ */
+ rtems_set_errno_and_return_minus_one( EBADF );
}
diff --git a/cpukit/posix/src/timergettime.c b/cpukit/posix/src/timergettime.c
index 3187dc8826..bb39121b81 100644
--- a/cpukit/posix/src/timergettime.c
+++ b/cpukit/posix/src/timergettime.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
@@ -40,6 +40,7 @@ int timer_gettime(
POSIX_Timer_Control *ptimer;
Objects_Locations location;
struct timespec current_time;
+ Watchdog_Interval left;
if ( !value )
rtems_set_errno_and_return_minus_one( EINVAL );
@@ -54,11 +55,11 @@ int timer_gettime(
/* Calculates the time left before the timer finishes */
- _Timespec_Subtract(
- &ptimer->timer_data.it_value,
- &current_time,
- &value->it_value
- );
+ left =
+ (ptimer->Timer.start_time + ptimer->Timer.initial) - /* expire */
+ _Watchdog_Ticks_since_boot; /* now */
+
+ _Timespec_From_ticks( left, &value->it_value );
value->it_interval = ptimer->timer_data.it_interval;
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: