summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-07-18 18:45:56 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-07-18 18:45:56 +0000
commit6a0898bba30ccd936e0ac1d6268970316efe92c4 (patch)
tree364d967bdfcdb75695666e37263cb2f0bed3a077 /cpukit
parentChanged special purpose register inline functions to macros. (diff)
downloadrtems-6a0898bba30ccd936e0ac1d6268970316efe92c4.tar.bz2
2008-07-18 Joel Sherrill <joel.sherrill@oarcorp.com>
PR 1291/cpukit * itron/inline/rtems/itron/semaphore.inl, itron/src/twai_sem.c, posix/include/mqueue.h, posix/include/rtems/posix/mqueue.h, posix/include/rtems/posix/semaphore.h, posix/include/rtems/posix/time.h, posix/src/condtimedwait.c, posix/src/mqueuereceive.c, posix/src/mqueuerecvsupp.c, posix/src/mqueuesend.c, posix/src/mqueuesendsupp.c, posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c, posix/src/mutextimedlock.c, posix/src/mutextranslatereturncode.c, posix/src/posixtimespecabsolutetimeout.c, posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c, posix/src/semaphoretranslatereturncode.c, posix/src/semaphorewaitsupp.c, posix/src/semtimedwait.c, posix/src/semtrywait.c, posix/src/semwait.c, posix/src/sigtimedwait.c, posix/src/timersettime.c, posix/src/ualarm.c, rtems/src/semobtain.c, rtems/src/semtranslatereturncode.c, score/include/rtems/score/coremutex.h, score/include/rtems/score/coresem.h, score/src/coresemseize.c: This patch addresses issues on implementation of the timeout on the following POSIX services. Some of these services incorrectly took a timeout as a relative time. Others would compute a 0 delta to timeout if the absolute time and the current time were equal and thus incorrectly block the caller forever. The root of the confusion is that POSIX specifies that if the timeout is incorrect (e.g. in the past, is now, or is numerically invalid), that it does not matter if the call would succeed without blocking. This is in contrast to RTEMS programming style where all errors are checked before any critical sections are entered. This fix implemented a more uniform way of handling POSIX absolute time timeouts. + pthread_cond_timedwait - could block forever + mq_timedreceive - used relative not absolute time + mq_timedsend - used relative not absolute time + pthread_mutex_timedlock - used relative not absolute time + pthread_rwlock_timedrdlock- used relative not absolute time + pthread_rwlock_timedwrlock- used relative not absolute time + sem_timedwait - could block forever
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/ChangeLog40
-rw-r--r--cpukit/itron/inline/rtems/itron/semaphore.inl2
-rw-r--r--cpukit/itron/src/twai_sem.c14
-rw-r--r--cpukit/posix/include/mqueue.h38
-rw-r--r--cpukit/posix/include/rtems/posix/mqueue.h4
-rw-r--r--cpukit/posix/include/rtems/posix/semaphore.h8
-rw-r--r--cpukit/posix/include/rtems/posix/time.h37
-rw-r--r--cpukit/posix/src/condtimedwait.c45
-rw-r--r--cpukit/posix/src/mqueuereceive.c3
-rw-r--r--cpukit/posix/src/mqueuerecvsupp.c20
-rw-r--r--cpukit/posix/src/mqueuesend.c3
-rw-r--r--cpukit/posix/src/mqueuesendsupp.c17
-rw-r--r--cpukit/posix/src/mqueuetimedreceive.c30
-rw-r--r--cpukit/posix/src/mqueuetimedsend.c30
-rw-r--r--cpukit/posix/src/mutextimedlock.c57
-rw-r--r--cpukit/posix/src/mutextranslatereturncode.c4
-rw-r--r--cpukit/posix/src/posixtimespecabsolutetimeout.c42
-rw-r--r--cpukit/posix/src/prwlocktimedrdlock.c47
-rw-r--r--cpukit/posix/src/prwlocktimedwrlock.c49
-rw-r--r--cpukit/posix/src/semaphoretranslatereturncode.c1
-rw-r--r--cpukit/posix/src/semaphorewaitsupp.c8
-rw-r--r--cpukit/posix/src/semtimedwait.c63
-rw-r--r--cpukit/posix/src/semtrywait.c4
-rw-r--r--cpukit/posix/src/semwait.c8
-rw-r--r--cpukit/posix/src/sigtimedwait.c11
-rw-r--r--cpukit/posix/src/timersettime.c3
-rw-r--r--cpukit/posix/src/ualarm.c4
-rw-r--r--cpukit/rtems/src/semobtain.c5
-rw-r--r--cpukit/rtems/src/semtranslatereturncode.c1
-rw-r--r--cpukit/score/include/rtems/score/coremutex.h2
-rw-r--r--cpukit/score/include/rtems/score/coresem.h42
-rw-r--r--cpukit/score/src/coresemseize.c43
32 files changed, 470 insertions, 215 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index 5fa3751e55..856336a87f 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,43 @@
+2008-07-18 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ PR 1291/cpukit
+ * itron/inline/rtems/itron/semaphore.inl, itron/src/twai_sem.c,
+ posix/include/mqueue.h, posix/include/rtems/posix/mqueue.h,
+ posix/include/rtems/posix/semaphore.h,
+ posix/include/rtems/posix/time.h, posix/src/condtimedwait.c,
+ posix/src/mqueuereceive.c, posix/src/mqueuerecvsupp.c,
+ posix/src/mqueuesend.c, posix/src/mqueuesendsupp.c,
+ posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c,
+ posix/src/mutextimedlock.c, posix/src/mutextranslatereturncode.c,
+ posix/src/posixtimespecabsolutetimeout.c,
+ posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c,
+ posix/src/semaphoretranslatereturncode.c,
+ posix/src/semaphorewaitsupp.c, posix/src/semtimedwait.c,
+ posix/src/semtrywait.c, posix/src/semwait.c,
+ posix/src/sigtimedwait.c, posix/src/timersettime.c,
+ posix/src/ualarm.c, rtems/src/semobtain.c,
+ rtems/src/semtranslatereturncode.c,
+ score/include/rtems/score/coremutex.h,
+ score/include/rtems/score/coresem.h, score/src/coresemseize.c: This
+ patch addresses issues on implementation of the timeout on the
+ following POSIX services. Some of these services incorrectly took a
+ timeout as a relative time. Others would compute a 0 delta to timeout
+ if the absolute time and the current time were equal and thus
+ incorrectly block the caller forever. The root of the confusion is
+ that POSIX specifies that if the timeout is incorrect (e.g. in the
+ past, is now, or is numerically invalid), that it does not matter if
+ the call would succeed without blocking. This is in contrast to RTEMS
+ programming style where all errors are checked before any critical
+ sections are entered. This fix implemented a more uniform way of
+ handling POSIX absolute time timeouts.
+ + pthread_cond_timedwait - could block forever
+ + mq_timedreceive - used relative not absolute time
+ + mq_timedsend - used relative not absolute time
+ + pthread_mutex_timedlock - used relative not absolute time
+ + pthread_rwlock_timedrdlock- used relative not absolute time
+ + pthread_rwlock_timedwrlock- used relative not absolute time
+ + sem_timedwait - could block forever
+
2008-07-17 Joel Sherrill <joel.sherrill@oarcorp.com>
* libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-object.c,
diff --git a/cpukit/itron/inline/rtems/itron/semaphore.inl b/cpukit/itron/inline/rtems/itron/semaphore.inl
index 1822fb8884..c57347f319 100644
--- a/cpukit/itron/inline/rtems/itron/semaphore.inl
+++ b/cpukit/itron/inline/rtems/itron/semaphore.inl
@@ -172,8 +172,6 @@ RTEMS_INLINE_ROUTINE ER _ITRON_Semaphore_Translate_core_semaphore_return_code (
return E_TMOUT;
case CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED:
return E_QOVR;
- case CORE_SEMAPHORE_BAD_TIMEOUT_VALUE:
- return E_PAR;
case THREAD_STATUS_PROXY_BLOCKING:
return THREAD_STATUS_PROXY_BLOCKING;
}
diff --git a/cpukit/itron/src/twai_sem.c b/cpukit/itron/src/twai_sem.c
index 9004c88e76..34d0694af2 100644
--- a/cpukit/itron/src/twai_sem.c
+++ b/cpukit/itron/src/twai_sem.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
@@ -30,16 +30,16 @@ ER twai_sem(
TMO tmout
)
{
- ITRON_Semaphore_Control *the_semaphore;
- Objects_Locations location;
- Watchdog_Interval interval;
- Core_semaphore_Blocking_option blocking;
+ ITRON_Semaphore_Control *the_semaphore;
+ Objects_Locations location;
+ Watchdog_Interval interval;
+ boolean blocking;
interval = 0;
if ( tmout == TMO_POL ) {
- blocking = CORE_SEMAPHORE_NO_WAIT;
+ blocking = FALSE;
} else {
- blocking = CORE_SEMAPHORE_BLOCK_FOREVER;
+ blocking = TRUE;
if ( tmout != TMO_FEVR )
interval = TOD_MILLISECONDS_TO_TICKS(tmout);
diff --git a/cpukit/posix/include/mqueue.h b/cpukit/posix/include/mqueue.h
index fe6975016d..c317d0c7bf 100644
--- a/cpukit/posix/include/mqueue.h
+++ b/cpukit/posix/include/mqueue.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
@@ -33,47 +33,53 @@ extern "C" {
* 15.1.1 Data Structures, P1003.1b-1993, p. 271
*/
+/**
+ * Message queue id type
+ */
typedef Objects_Id mqd_t;
+/**
+ * This is the message queue attributes structure.
+ */
struct mq_attr {
- long mq_flags; /* Message queue flags */
- long mq_maxmsg; /* Maximum number of messages */
- long mq_msgsize; /* Maximum message size */
- long mq_curmsgs; /* Number of messages currently queued */
+ /** This is the message queue flags */
+ long mq_flags;
+ /** This is the maximum number of messages */
+ long mq_maxmsg;
+ /** This is the maximum message size */
+ long mq_msgsize;
+ /** This is the mumber of messages currently queued */
+ long mq_curmsgs;
};
-/*
+/**
* 15.2.2 Open a Message Queue, P1003.1b-1993, p. 272
*/
-
mqd_t mq_open(
const char *name,
int oflag,
...
);
-/*
+/**
* 15.2.2 Close a Message Queue, P1003.1b-1993, p. 275
*/
-
int mq_close(
mqd_t mqdes
);
-/*
+/**
* 15.2.2 Remove a Message Queue, P1003.1b-1993, p. 276
*/
-
int mq_unlink(
const char *name
);
-/*
+/**
* 15.2.4 Send a Message to a Message Queue, P1003.1b-1993, p. 277
*
- * NOTE: P1003.4b/D8, p. 45 adds mq_timedsend().
+ * @note P1003.4b/D8, p. 45 adds mq_timedsend().
*/
-
int mq_send(
mqd_t mqdes,
const char *msg_ptr,
@@ -90,7 +96,7 @@ int mq_timedsend(
const char *msg_ptr,
size_t msg_len,
unsigned int msg_prio,
- const struct timespec *timeout
+ const struct timespec *abstime
);
#endif /* _POSIX_TIMEOUTS */
@@ -115,7 +121,7 @@ ssize_t mq_timedreceive(
char *msg_ptr,
size_t msg_len,
unsigned int *msg_prio,
- const struct timespec *timeout
+ const struct timespec *abstime
);
#endif /* _POSIX_TIMEOUTS */
diff --git a/cpukit/posix/include/rtems/posix/mqueue.h b/cpukit/posix/include/rtems/posix/mqueue.h
index 475f9a2432..67dda09d93 100644
--- a/cpukit/posix/include/rtems/posix/mqueue.h
+++ b/cpukit/posix/include/rtems/posix/mqueue.h
@@ -6,7 +6,7 @@
*/
/*
- * COPYRIGHT (c) 1989-1999.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -112,6 +112,7 @@ ssize_t _POSIX_Message_queue_Receive_support(
char *msg_ptr,
size_t msg_len,
unsigned int *msg_prio,
+ boolean wait,
Watchdog_Interval timeout
);
@@ -128,6 +129,7 @@ int _POSIX_Message_queue_Send_support(
const char *msg_ptr,
size_t msg_len,
uint32_t msg_prio,
+ boolean wait,
Watchdog_Interval timeout
);
diff --git a/cpukit/posix/include/rtems/posix/semaphore.h b/cpukit/posix/include/rtems/posix/semaphore.h
index 804a8bd0e3..f345aed8bd 100644
--- a/cpukit/posix/include/rtems/posix/semaphore.h
+++ b/cpukit/posix/include/rtems/posix/semaphore.h
@@ -7,7 +7,7 @@
* This include file contains all the private support information for
* POSIX Semaphores.
*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -153,9 +153,9 @@ void _POSIX_Semaphore_Delete(
*/
int _POSIX_Semaphore_Wait_support(
- sem_t *sem,
- Core_semaphore_Blocking_option blocking,
- Watchdog_Interval timeout
+ sem_t *sem,
+ boolean blocking,
+ Watchdog_Interval timeout
);
/*
diff --git a/cpukit/posix/include/rtems/posix/time.h b/cpukit/posix/include/rtems/posix/time.h
index 8f4d4b6257..0782996399 100644
--- a/cpukit/posix/include/rtems/posix/time.h
+++ b/cpukit/posix/include/rtems/posix/time.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
@@ -18,10 +18,39 @@
#include <rtems/score/timespec.h>
-/*
- * _POSIX_Absolute_timeout_to_ticks
+/** @brief Absolute Timeout Conversion Results
+ *
+ * This enumeration defines the possible results of converting
+ * an absolute time used for timeouts to POSIX blocking calls to
+ * a number of ticks.
+ */
+typedef enum {
+ /** The timeout is invalid. */
+ POSIX_ABSOLUTE_TIMEOUT_INVALID,
+ /** The timeout represents a time that is in the past. */
+ POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST,
+ /** The timeout represents a time that is equal to the current time. */
+ POSIX_ABSOLUTE_TIMEOUT_IS_NOW,
+ /** The timeout represents a time that is in the future. */
+ POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE,
+} POSIX_Absolute_timeout_conversion_results_t;
+
+/**
+ * @brief Convert Absolute Timeout to Ticks
+ *
+ * This method takes an absolute time being used as a timeout
+ * to a blocking directive, validates it and returns the number
+ * of corresponding clock ticks for use by the SuperCore.
+ *
+ * @param[in] abstime is the timeout
+ * @param[in] ticks_out will contain the number of ticks
+ *
+ * @return This method returns the number of ticks in @a ticks_out
+ * and a status value indicating whether the absolute time
+ * is valid, in the past, equal to the current time or in
+ * the future as it should be.
*/
-int _POSIX_Absolute_timeout_to_ticks(
+POSIX_Absolute_timeout_conversion_results_t _POSIX_Absolute_timeout_to_ticks(
const struct timespec *abstime,
Watchdog_Interval *ticks_out
);
diff --git a/cpukit/posix/src/condtimedwait.c b/cpukit/posix/src/condtimedwait.c
index 717851a8c8..ef615b7d1d 100644
--- a/cpukit/posix/src/condtimedwait.c
+++ b/cpukit/posix/src/condtimedwait.c
@@ -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
@@ -39,37 +39,34 @@ int pthread_cond_timedwait(
const struct timespec *abstime
)
{
- Watchdog_Interval timeout;
- struct timespec current_time;
- struct timespec difference;
- boolean already_timedout = FALSE;
-
- if ( !_Timespec_Is_valid(abstime) )
- return EINVAL;
-
- /*
- * The abstime is a walltime. We turn it into an interval.
- */
-
- _TOD_Get( &current_time );
+ Watchdog_Interval ticks;
+ boolean already_timedout;
/*
- * Make sure the timeout is in the future
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
*/
- if ( _Timespec_Less_than( abstime, &current_time ) ) {
- already_timedout = TRUE;
- difference.tv_sec = 0;
- difference.tv_nsec = 0;
- timeout = 0;
- } else {
- _Timespec_Subtract( &current_time, abstime, &difference );
- timeout = _Timespec_To_ticks( &difference );
+ switch ( _POSIX_Absolute_timeout_to_ticks(abstime, &ticks) ) {
+ case POSIX_ABSOLUTE_TIMEOUT_INVALID:
+ return EINVAL;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
+ already_timedout = TRUE;
+ break;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
+ already_timedout = FALSE;
+ break;
}
return _POSIX_Condition_variables_Wait_support(
cond,
mutex,
- timeout,
+ ticks,
already_timedout
);
}
diff --git a/cpukit/posix/src/mqueuereceive.c b/cpukit/posix/src/mqueuereceive.c
index ef5a42f743..e27f3ccd48 100644
--- a/cpukit/posix/src/mqueuereceive.c
+++ b/cpukit/posix/src/mqueuereceive.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
@@ -58,6 +58,7 @@ ssize_t mq_receive(
msg_ptr,
msg_len,
msg_prio,
+ TRUE,
THREAD_QUEUE_WAIT_FOREVER
);
}
diff --git a/cpukit/posix/src/mqueuerecvsupp.c b/cpukit/posix/src/mqueuerecvsupp.c
index d42f632889..08d7fbc0a5 100644
--- a/cpukit/posix/src/mqueuerecvsupp.c
+++ b/cpukit/posix/src/mqueuerecvsupp.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
@@ -39,8 +39,7 @@
#include <rtems/posix/mqueue.h>
#include <rtems/posix/time.h>
-/*PAGE
- *
+/*
* _POSIX_Message_queue_Receive_support
*
* NOTE: XXX Document how size, priority, length, and the buffer go
@@ -52,6 +51,7 @@ ssize_t _POSIX_Message_queue_Receive_support(
char *msg_ptr,
size_t msg_len,
unsigned int *msg_prio,
+ boolean wait,
Watchdog_Interval timeout
)
{
@@ -59,6 +59,7 @@ ssize_t _POSIX_Message_queue_Receive_support(
POSIX_Message_queue_Control_fd *the_mq_fd;
Objects_Locations location;
size_t length_out;
+ boolean do_wait;
the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
switch ( location ) {
@@ -83,12 +84,23 @@ ssize_t _POSIX_Message_queue_Receive_support(
length_out = -1;
+ /*
+ * A timed receive with a bad time will do a poll regardless.
+ */
+ if ( wait )
+ do_wait = (the_mq_fd->oflag & O_NONBLOCK) ? FALSE : TRUE;
+ else
+ do_wait = wait;
+
+ /*
+ * Now perform the actual message receive
+ */
_CORE_message_queue_Seize(
&the_mq->Message_queue,
mqdes,
msg_ptr,
&length_out,
- (the_mq_fd->oflag & O_NONBLOCK) ? FALSE : TRUE,
+ do_wait,
timeout
);
diff --git a/cpukit/posix/src/mqueuesend.c b/cpukit/posix/src/mqueuesend.c
index 6fe19a08cf..61e7c93b53 100644
--- a/cpukit/posix/src/mqueuesend.c
+++ b/cpukit/posix/src/mqueuesend.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
@@ -58,6 +58,7 @@ int mq_send(
msg_ptr,
msg_len,
msg_prio,
+ TRUE,
THREAD_QUEUE_WAIT_FOREVER
);
}
diff --git a/cpukit/posix/src/mqueuesendsupp.c b/cpukit/posix/src/mqueuesendsupp.c
index 5b437b04e5..8a593c816c 100644
--- a/cpukit/posix/src/mqueuesendsupp.c
+++ b/cpukit/posix/src/mqueuesendsupp.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
@@ -50,6 +50,7 @@ int _POSIX_Message_queue_Send_support(
const char *msg_ptr,
size_t msg_len,
uint32_t msg_prio,
+ boolean wait,
Watchdog_Interval timeout
)
{
@@ -57,6 +58,7 @@ int _POSIX_Message_queue_Send_support(
POSIX_Message_queue_Control_fd *the_mq_fd;
Objects_Locations location;
CORE_message_queue_Status msg_status;
+ boolean do_wait;
/*
* Validate the priority.
@@ -77,6 +79,17 @@ int _POSIX_Message_queue_Send_support(
the_mq = the_mq_fd->Queue;
+ /*
+ * A timed receive with a bad time will do a poll regardless.
+ */
+ if ( wait )
+ do_wait = (the_mq_fd->oflag & O_NONBLOCK) ? FALSE : TRUE;
+ else
+ do_wait = wait;
+
+ /*
+ * Now perform the actual message receive
+ */
msg_status = _CORE_message_queue_Submit(
&the_mq->Message_queue,
(void *)msg_ptr,
@@ -84,7 +97,7 @@ int _POSIX_Message_queue_Send_support(
mqdes, /* mqd_t is an object id */
NULL,
_POSIX_Message_queue_Priority_to_core( msg_prio ),
- (the_mq_fd->oflag & O_NONBLOCK) ? FALSE : TRUE,
+ do_wait,
timeout /* no timeout */
);
diff --git a/cpukit/posix/src/mqueuetimedreceive.c b/cpukit/posix/src/mqueuetimedreceive.c
index 493ac7aa66..4a16328c79 100644
--- a/cpukit/posix/src/mqueuetimedreceive.c
+++ b/cpukit/posix/src/mqueuetimedreceive.c
@@ -13,7 +13,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
@@ -53,14 +53,38 @@ ssize_t mq_timedreceive(
char *msg_ptr,
size_t msg_len,
unsigned int *msg_prio,
- const struct timespec *timeout
+ const struct timespec *abstime
)
{
+ Watchdog_Interval ticks;
+ boolean do_wait;
+
+ /*
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
+ */
+ switch ( _POSIX_Absolute_timeout_to_ticks( abstime, &ticks ) ) {
+ case POSIX_ABSOLUTE_TIMEOUT_INVALID:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
+ do_wait = FALSE;
+ break;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
+ do_wait = TRUE;
+ break;
+ }
+
return _POSIX_Message_queue_Receive_support(
mqdes,
msg_ptr,
msg_len,
msg_prio,
- _Timespec_To_ticks( timeout )
+ do_wait,
+ ticks
);
}
diff --git a/cpukit/posix/src/mqueuetimedsend.c b/cpukit/posix/src/mqueuetimedsend.c
index 262bf8baa9..dbe952aea0 100644
--- a/cpukit/posix/src/mqueuetimedsend.c
+++ b/cpukit/posix/src/mqueuetimedsend.c
@@ -13,7 +13,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
@@ -53,14 +53,38 @@ int mq_timedsend(
const char *msg_ptr,
size_t msg_len,
unsigned int msg_prio,
- const struct timespec *timeout
+ const struct timespec *abstime
)
{
+ Watchdog_Interval ticks;
+ boolean do_wait;
+
+ /*
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
+ */
+ switch ( _POSIX_Absolute_timeout_to_ticks( abstime, &ticks ) ) {
+ case POSIX_ABSOLUTE_TIMEOUT_INVALID:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
+ do_wait = FALSE;
+ break;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
+ do_wait = TRUE;
+ break;
+ }
+
return _POSIX_Message_queue_Send_support(
mqdes,
msg_ptr,
msg_len,
msg_prio,
- _Timespec_To_ticks( timeout )
+ do_wait,
+ ticks
);
}
diff --git a/cpukit/posix/src/mutextimedlock.c b/cpukit/posix/src/mutextimedlock.c
index 85a1782114..5eae6eae76 100644
--- a/cpukit/posix/src/mutextimedlock.c
+++ b/cpukit/posix/src/mutextimedlock.c
@@ -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
@@ -39,13 +39,58 @@
int pthread_mutex_timedlock(
pthread_mutex_t *mutex,
- const struct timespec *timeout
+ const struct timespec *abstime
)
{
- /* XXX does timeout need to be based on CLOCK_REALTIME and be TOD? */
- return _POSIX_Mutex_Lock_support(
+ Watchdog_Interval ticks;
+ boolean do_wait;
+ POSIX_Absolute_timeout_conversion_results_t status;
+ int lock_status;
+
+ /*
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
+ */
+ status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
+ switch ( status ) {
+ case POSIX_ABSOLUTE_TIMEOUT_INVALID:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
+ do_wait = FALSE;
+ break;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
+ do_wait = TRUE;
+ break;
+ }
+
+ lock_status = _POSIX_Mutex_Lock_support(
mutex,
- TRUE,
- _Timespec_To_ticks( timeout )
+ do_wait,
+ ticks
);
+
+ /*
+ * This service only gives us the option to block. We used a polling
+ * attempt to lock if the abstime was not in the future. If we did
+ * not obtain the mutex, then not look at the status immediately,
+ * make sure the right reason is returned.
+ */
+ if ( !do_wait && (lock_status == EBUSY) ) {
+ switch (lock_status) {
+ case POSIX_ABSOLUTE_TIMEOUT_INVALID:
+ return EINVAL;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
+ return ETIMEDOUT;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
+ break;
+ }
+ }
+
+ return lock_status;
}
diff --git a/cpukit/posix/src/mutextranslatereturncode.c b/cpukit/posix/src/mutextranslatereturncode.c
index 7c335e7e4b..d2a684bfe0 100644
--- a/cpukit/posix/src/mutextranslatereturncode.c
+++ b/cpukit/posix/src/mutextranslatereturncode.c
@@ -1,7 +1,7 @@
/*
* POSIX Mutex Error Translation
*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -38,7 +38,7 @@ static int _POSIX_Mutex_Return_codes[CORE_MUTEX_STATUS_LAST + 1] = {
EDEADLK, /* CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED */
EPERM, /* CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE */
EINVAL, /* CORE_MUTEX_WAS_DELETED */
- EAGAIN, /* CORE_MUTEX_TIMEOUT */
+ ETIMEDOUT, /* CORE_MUTEX_TIMEOUT */
EINVAL /* CORE_MUTEX_STATUS_CEILING_VIOLATED */
};
diff --git a/cpukit/posix/src/posixtimespecabsolutetimeout.c b/cpukit/posix/src/posixtimespecabsolutetimeout.c
index 52208e380b..036fd9ee8b 100644
--- a/cpukit/posix/src/posixtimespecabsolutetimeout.c
+++ b/cpukit/posix/src/posixtimespecabsolutetimeout.c
@@ -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
@@ -34,7 +34,7 @@
/*
* The abstime is a walltime. We turn it into an interval.
*/
-int _POSIX_Absolute_timeout_to_ticks(
+POSIX_Absolute_timeout_conversion_results_t _POSIX_Absolute_timeout_to_ticks(
const struct timespec *abstime,
Watchdog_Interval *ticks_out
)
@@ -42,21 +42,47 @@ int _POSIX_Absolute_timeout_to_ticks(
struct timespec current_time;
struct timespec difference;
- if ( !_Timespec_Is_valid(abstime) )
- return EINVAL;
+
+ /*
+ * Make sure there is always a value returned.
+ */
+ *ticks_out = 0;
- _TOD_Get( &current_time );
+ /*
+ * Is the absolute time even valid?
+ */
+ if ( !_Timespec_Is_valid(abstime) )
+ return POSIX_ABSOLUTE_TIMEOUT_INVALID;
/*
- * Make sure the abstime is in the future
+ * Is the absolute time in the past?
*/
+ _TOD_Get( &current_time );
+
if ( _Timespec_Less_than( abstime, &current_time ) )
- return EINVAL;
+ return POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST;
+ /*
+ * How long until the requested absolute time?
+ */
_Timespec_Subtract( &current_time, abstime, &difference );
+ /*
+ * Internally the SuperCore uses ticks, so convert to them.
+ */
*ticks_out = _Timespec_To_ticks( &difference );
- return 0;
+ /*
+ * If the difference was 0, then the future is now. It is so bright
+ * we better wear shades.
+ */
+ if ( !*ticks_out )
+ return POSIX_ABSOLUTE_TIMEOUT_IS_NOW;
+
+ /*
+ * This is the case we were expecting and it took this long to
+ * get here.
+ */
+ return POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE;
}
diff --git a/cpukit/posix/src/prwlocktimedrdlock.c b/cpukit/posix/src/prwlocktimedrdlock.c
index 15ddbf791b..52462acab6 100644
--- a/cpukit/posix/src/prwlocktimedrdlock.c
+++ b/cpukit/posix/src/prwlocktimedrdlock.c
@@ -1,7 +1,7 @@
/*
* POSIX RWLock Manager -- Attempt to Obtain a Read Lock on a RWLock Instance
*
- * 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,17 +40,35 @@ int pthread_rwlock_timedrdlock(
const struct timespec *abstime
)
{
- POSIX_RWLock_Control *the_rwlock;
- Objects_Locations location;
- Watchdog_Interval ticks;
- int status;
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+ Watchdog_Interval ticks;
+ boolean do_wait;
+ POSIX_Absolute_timeout_conversion_results_t status;
if ( !rwlock )
return EINVAL;
+ /*
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
+ */
status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
- if ( status )
- return status;
+ switch (status) {
+ case POSIX_ABSOLUTE_TIMEOUT_INVALID:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
+ do_wait = FALSE;
+ break;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
+ do_wait = TRUE;
+ break;
+ }
the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
switch ( location ) {
@@ -60,12 +78,25 @@ int pthread_rwlock_timedrdlock(
_CORE_RWLock_Obtain_for_reading(
&the_rwlock->RWLock,
*rwlock,
- TRUE, // we are willing to wait up to ticks
+ do_wait,
ticks,
NULL
);
_Thread_Enable_dispatch();
+ if ( !do_wait &&
+ (_Thread_Executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE) ) {
+ switch (status) {
+ case POSIX_ABSOLUTE_TIMEOUT_INVALID:
+ return EINVAL;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
+ return ETIMEDOUT;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
+ break;
+ }
+ }
+
return _POSIX_RWLock_Translate_core_RWLock_return_code(
(CORE_RWLock_Status) _Thread_Executing->Wait.return_code
);
diff --git a/cpukit/posix/src/prwlocktimedwrlock.c b/cpukit/posix/src/prwlocktimedwrlock.c
index adf45b77fc..a826df8371 100644
--- a/cpukit/posix/src/prwlocktimedwrlock.c
+++ b/cpukit/posix/src/prwlocktimedwrlock.c
@@ -1,7 +1,7 @@
/*
* POSIX RWLock Manager -- Attempt to Obtain a Write Lock on a RWLock Instance
*
- * 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,17 +40,35 @@ int pthread_rwlock_timedwrlock(
const struct timespec *abstime
)
{
- POSIX_RWLock_Control *the_rwlock;
- Objects_Locations location;
- int status;
- Watchdog_Interval ticks;
-
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+ Watchdog_Interval ticks;
+ boolean do_wait;
+ POSIX_Absolute_timeout_conversion_results_t status;
+
if ( !rwlock )
return EINVAL;
+ /*
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
+ */
status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
- if ( status )
- return status;
+ switch (status) {
+ case POSIX_ABSOLUTE_TIMEOUT_INVALID:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
+ do_wait = FALSE;
+ break;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
+ do_wait = TRUE;
+ break;
+ }
the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
switch ( location ) {
@@ -60,12 +78,25 @@ int pthread_rwlock_timedwrlock(
_CORE_RWLock_Obtain_for_writing(
&the_rwlock->RWLock,
*rwlock,
- TRUE, // we are willing to wait up to ticks
+ do_wait,
ticks,
NULL
);
_Thread_Enable_dispatch();
+ if ( !do_wait &&
+ (_Thread_Executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE) ) {
+ switch (status) {
+ case POSIX_ABSOLUTE_TIMEOUT_INVALID:
+ return EINVAL;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
+ return ETIMEDOUT;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
+ break;
+ }
+ }
+
return _POSIX_RWLock_Translate_core_RWLock_return_code(
(CORE_RWLock_Status) _Thread_Executing->Wait.return_code
);
diff --git a/cpukit/posix/src/semaphoretranslatereturncode.c b/cpukit/posix/src/semaphoretranslatereturncode.c
index 9961470f50..c87f5c93c8 100644
--- a/cpukit/posix/src/semaphoretranslatereturncode.c
+++ b/cpukit/posix/src/semaphoretranslatereturncode.c
@@ -41,7 +41,6 @@ static int _POSIX_Semaphore_Return_codes[CORE_SEMAPHORE_STATUS_LAST + 1] = {
* count to the largest value the count can hold.
*/
ENOSYS, /* CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED */
- EINVAL /* CORE_SEMAPHORE_BAD_TIMEOUT_VALUE */
};
diff --git a/cpukit/posix/src/semaphorewaitsupp.c b/cpukit/posix/src/semaphorewaitsupp.c
index 7a7b2bbf1b..d1a506cb04 100644
--- a/cpukit/posix/src/semaphorewaitsupp.c
+++ b/cpukit/posix/src/semaphorewaitsupp.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
@@ -33,9 +33,9 @@
*/
int _POSIX_Semaphore_Wait_support(
- sem_t *sem,
- Core_semaphore_Blocking_option blocking,
- Watchdog_Interval timeout
+ sem_t *sem,
+ boolean blocking,
+ Watchdog_Interval timeout
)
{
POSIX_Semaphore_Control *the_semaphore;
diff --git a/cpukit/posix/src/semtimedwait.c b/cpukit/posix/src/semtimedwait.c
index 6b93b9232b..b76fa17a81 100644
--- a/cpukit/posix/src/semtimedwait.c
+++ b/cpukit/posix/src/semtimedwait.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,32 +39,51 @@ int sem_timedwait(
const struct timespec *abstime
)
{
+ Watchdog_Interval ticks;
+ boolean do_wait = TRUE;
+ POSIX_Absolute_timeout_conversion_results_t status;
+ int lock_status;
+
/*
- * The abstime is a walltime. We turn it into an interval.
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
*/
- Watchdog_Interval ticks = 0;
- struct timespec current_time;
- struct timespec difference;
- Core_semaphore_Blocking_option blocking = CORE_SEMAPHORE_BLOCK_WITH_TIMEOUT;
+ status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
+ switch ( status ) {
+ case POSIX_ABSOLUTE_TIMEOUT_INVALID:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
+ do_wait = FALSE;
+ break;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
+ do_wait = TRUE;
+ break;
+ }
+
+ lock_status = _POSIX_Semaphore_Wait_support( sem, do_wait, ticks );
/*
- * Error check the absolute time to timeout
+ * This service only gives us the option to block. We used a polling
+ * attempt to obtain if the abstime was not in the future. If we did
+ * not obtain the semaphore, then not look at the status immediately,
+ * make sure the right reason is returned.
*/
- if ( !_Timespec_Is_valid( abstime ) ) {
- blocking = CORE_SEMAPHORE_BAD_TIMEOUT_VALUE;
- } else {
- _TOD_Get( &current_time );
- /*
- * Make sure the abstime is in the future
- */
- if ( _Timespec_Less_than( abstime, &current_time ) ) {
- blocking = CORE_SEMAPHORE_BAD_TIMEOUT;
- } else {
- _Timespec_Subtract( &current_time, abstime, &difference );
- ticks = _Timespec_To_ticks( &difference );
- blocking = CORE_SEMAPHORE_BLOCK_WITH_TIMEOUT;
+ if ( !do_wait && (lock_status == EBUSY) ) {
+ switch (lock_status) {
+ case POSIX_ABSOLUTE_TIMEOUT_INVALID:
+ return EINVAL;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
+ case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
+ return ETIMEDOUT;
+ case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
+ break;
}
- }
+ }
- return _POSIX_Semaphore_Wait_support( sem, blocking, ticks );
+ return lock_status;
}
diff --git a/cpukit/posix/src/semtrywait.c b/cpukit/posix/src/semtrywait.c
index c7ffc3321d..473bf78852 100644
--- a/cpukit/posix/src/semtrywait.c
+++ b/cpukit/posix/src/semtrywait.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
@@ -38,5 +38,5 @@ int sem_trywait(
sem_t *sem
)
{
- return _POSIX_Semaphore_Wait_support( sem, FALSE, THREAD_QUEUE_WAIT_FOREVER );
+ return _POSIX_Semaphore_Wait_support(sem, FALSE, THREAD_QUEUE_WAIT_FOREVER);
}
diff --git a/cpukit/posix/src/semwait.c b/cpukit/posix/src/semwait.c
index c2f73d1536..d9bb81e5ff 100644
--- a/cpukit/posix/src/semwait.c
+++ b/cpukit/posix/src/semwait.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
@@ -38,9 +38,5 @@ int sem_wait(
sem_t *sem
)
{
- return _POSIX_Semaphore_Wait_support(
- sem,
- CORE_SEMAPHORE_BLOCK_FOREVER,
- THREAD_QUEUE_WAIT_FOREVER
- );
+ return _POSIX_Semaphore_Wait_support( sem, TRUE, THREAD_QUEUE_WAIT_FOREVER );
}
diff --git a/cpukit/posix/src/sigtimedwait.c b/cpukit/posix/src/sigtimedwait.c
index 311e6cc90a..45571e24a4 100644
--- a/cpukit/posix/src/sigtimedwait.c
+++ b/cpukit/posix/src/sigtimedwait.c
@@ -1,7 +1,7 @@
/*
* 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76
*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -63,16 +63,21 @@ int sigtimedwait(
/*
* Error check parameters before disabling interrupts.
+ *
+ * NOTE: This is very specifically a RELATIVE not ABSOLUTE time
+ * in the Open Group specification.
*/
interval = 0;
if ( timeout ) {
- if ( !_Timespec_Is_valid( timeout ) ) {
+ if ( !_Timespec_Is_valid( timeout ) )
rtems_set_errno_and_return_minus_one( EINVAL );
- }
interval = _Timespec_To_ticks( timeout );
+
+ if ( !interval )
+ rtems_set_errno_and_return_minus_one( EINVAL );
}
/*
diff --git a/cpukit/posix/src/timersettime.c b/cpukit/posix/src/timersettime.c
index e55a18ef07..bbac472aa6 100644
--- a/cpukit/posix/src/timersettime.c
+++ b/cpukit/posix/src/timersettime.c
@@ -59,8 +59,9 @@ int timer_settime(
/* Check for seconds in the past */
if ( _Timespec_Greater_than( &normalize.it_value, &_TOD_Now ) )
rtems_set_errno_and_return_minus_one( EINVAL );
- _Timespec_Subtract( &_TOD_Now, &normalize.it_value, &normalize.it_value);
+ _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
diff --git a/cpukit/posix/src/ualarm.c b/cpukit/posix/src/ualarm.c
index 1de1621b1a..55bac1052b 100644
--- a/cpukit/posix/src/ualarm.c
+++ b/cpukit/posix/src/ualarm.c
@@ -1,7 +1,7 @@
/*
* 3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -101,9 +101,9 @@ useconds_t ualarm(
tp.tv_sec = useconds / TOD_MICROSECONDS_PER_SECOND;
tp.tv_nsec = (useconds % TOD_MICROSECONDS_PER_SECOND) * 1000;
ticks = _Timespec_To_ticks( &tp );
-
if ( ticks == 0 )
ticks = 1;
+
_Watchdog_Insert_ticks( the_timer, _Timespec_To_ticks( &tp ) );
}
diff --git a/cpukit/rtems/src/semobtain.c b/cpukit/rtems/src/semobtain.c
index b1909585dd..8ab51bf3c8 100644
--- a/cpukit/rtems/src/semobtain.c
+++ b/cpukit/rtems/src/semobtain.c
@@ -15,7 +15,7 @@
* + acquire a semaphore
* + release a semaphore
*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -95,8 +95,7 @@ rtems_status_code rtems_semaphore_obtain(
_CORE_semaphore_Seize_isr_disable(
&the_semaphore->Core_control.semaphore,
id,
- ((_Options_Is_no_wait( option_set )) ?
- CORE_SEMAPHORE_NO_WAIT : CORE_SEMAPHORE_BLOCK_FOREVER),
+ ((_Options_Is_no_wait( option_set )) ? FALSE : TRUE),
timeout,
&level
);
diff --git a/cpukit/rtems/src/semtranslatereturncode.c b/cpukit/rtems/src/semtranslatereturncode.c
index 94cbbab726..19ee8e7b81 100644
--- a/cpukit/rtems/src/semtranslatereturncode.c
+++ b/cpukit/rtems/src/semtranslatereturncode.c
@@ -115,7 +115,6 @@ const rtems_status_code _Semaphore_Translate_core_semaphore_return_code_[] = {
RTEMS_OBJECT_WAS_DELETED, /* CORE_SEMAPHORE_WAS_DELETED */
RTEMS_TIMEOUT, /* CORE_SEMAPHORE_TIMEOUT */
RTEMS_INTERNAL_ERROR, /* CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED */
- RTEMS_INTERNAL_ERROR /* CORE_SEMAPHORE_BAD_TIMEOUT_VALUE */
};
rtems_status_code _Semaphore_Translate_core_semaphore_return_code (
diff --git a/cpukit/score/include/rtems/score/coremutex.h b/cpukit/score/include/rtems/score/coremutex.h
index cc059fa61d..727f2200c2 100644
--- a/cpukit/score/include/rtems/score/coremutex.h
+++ b/cpukit/score/include/rtems/score/coremutex.h
@@ -41,7 +41,6 @@ extern "C" {
#include <rtems/score/interr.h>
#include <rtems/score/sysstate.h>
-
/**
* @brief MP Support Callback Prototype
*
@@ -411,6 +410,7 @@ void _CORE_mutex_Seize_interrupt_blocking(
#define _CORE_mutex_Seize( _the_mutex, _id, _wait, _timeout, _level ) \
_CORE_mutex_Seize_body( _the_mutex, _id, _wait, _timeout, _level )
#endif
+
/**
* @brief Surrender the Mutex
*
diff --git a/cpukit/score/include/rtems/score/coresem.h b/cpukit/score/include/rtems/score/coresem.h
index 9a0436b29a..fc2f979ff5 100644
--- a/cpukit/score/include/rtems/score/coresem.h
+++ b/cpukit/score/include/rtems/score/coresem.h
@@ -8,7 +8,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
@@ -82,14 +82,7 @@ typedef enum {
/** This status indicates that an attempt was made to unlock the semaphore
* and this would have made its count greater than that allowed.
*/
- CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED,
- /** This status indicates that the semaphore was not immediately
- * available and the caller passed a bad timeout value to the API
- * routine. In this case, the API required that the validity check
- * for the timeout occur after the check that the semaphore was immediately
- * available.
- */
- CORE_SEMAPHORE_BAD_TIMEOUT_VALUE
+ CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED
} CORE_semaphore_Status;
/**
@@ -97,7 +90,7 @@ typedef enum {
*
* This is the last status value.
*/
-#define CORE_SEMAPHORE_STATUS_LAST CORE_SEMAPHORE_BAD_TIMEOUT_VALUE
+#define CORE_SEMAPHORE_STATUS_LAST CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED
/**
* The following defines the control block used to manage the
@@ -130,25 +123,6 @@ typedef struct {
} CORE_semaphore_Control;
/**
- * The following enumerated type is the set of blocking options
- * available to seize operation.
- */
-typedef enum {
- /** This value indicates that the caller does not wish to block. */
- CORE_SEMAPHORE_NO_WAIT,
- /** This value indicates that the caller is willing to block forever. */
- CORE_SEMAPHORE_BLOCK_FOREVER,
- /** This value indicates that the caller is blocking with a timeout. */
- CORE_SEMAPHORE_BLOCK_WITH_TIMEOUT,
- /** This value indicates that the caller wanted to block but passed in
- * a bad timeout value to the API. Unfortunately, this is a weird case
- * where the timeout bad error is required to be generated only if
- * the semaphore is not available.
- */
- CORE_SEMAPHORE_BAD_TIMEOUT
-} Core_semaphore_Blocking_option;
-
-/**
* This routine initializes the semaphore based on the parameters passed.
*
* @param[in] the_semaphore is the semaphore to initialize
@@ -170,15 +144,15 @@ void _CORE_semaphore_Initialize(
* @param[in] the_semaphore is the semaphore to seize
* @param[in] id is the Id of the API level Semaphore object associated
* with this instance of a SuperCore Semaphore
- * @param[in] wait is the blocking mode
+ * @param[in] wait indicates if the caller is willing to block
* @param[in] timeout is the number of ticks the calling thread is willing
* to wait if @a wait is TRUE.
*/
void _CORE_semaphore_Seize(
- CORE_semaphore_Control *the_semaphore,
- Objects_Id id,
- Core_semaphore_Blocking_option wait,
- Watchdog_Interval timeout
+ CORE_semaphore_Control *the_semaphore,
+ Objects_Id id,
+ boolean wait,
+ Watchdog_Interval timeout
);
/**
diff --git a/cpukit/score/src/coresemseize.c b/cpukit/score/src/coresemseize.c
index 6fd59b8d57..1db77199ba 100644
--- a/cpukit/score/src/coresemseize.c
+++ b/cpukit/score/src/coresemseize.c
@@ -51,10 +51,10 @@
*/
void _CORE_semaphore_Seize(
- CORE_semaphore_Control *the_semaphore,
- Objects_Id id,
- Core_semaphore_Blocking_option wait,
- Watchdog_Interval timeout
+ CORE_semaphore_Control *the_semaphore,
+ Objects_Id id,
+ boolean wait,
+ Watchdog_Interval timeout
)
{
Thread_Control *executing;
@@ -74,36 +74,19 @@ void _CORE_semaphore_Seize(
* to block, then return immediately with a status indicating that
* the semaphore was not available and the caller never blocked.
*/
- if ( wait == CORE_SEMAPHORE_NO_WAIT ) {
- _ISR_Enable( level );
- executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
- return;
- }
-
- /*
- * This is strange case because normally RTEMS validates parameters
- * before performing any real work. But in this case, the POSIX
- * API requires that a semaphore be checked for immediate availability
- * BEFORE the timeout value is validated. This is implemented in
- * RTEMS by indicating a special status that the timeout value
- * was invalid which is returned in this case.
- */
- if ( wait == CORE_SEMAPHORE_BAD_TIMEOUT ) {
- _ISR_Enable( level );
- executing->Wait.return_code = CORE_SEMAPHORE_BAD_TIMEOUT_VALUE;
- return;
+ if ( !wait ) {
+ _ISR_Enable( level );
+ executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
+ return;
}
/*
* If the semaphore is not available and the caller is willing to
* block, then we now block the caller with optional timeout.
*/
- if (( wait == CORE_SEMAPHORE_BLOCK_FOREVER) ||
- ( wait == CORE_SEMAPHORE_BLOCK_WITH_TIMEOUT ) ) {
- _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue );
- executing->Wait.queue = &the_semaphore->Wait_queue;
- executing->Wait.id = id;
- _ISR_Enable( level );
- _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout );
- }
+ _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue );
+ executing->Wait.queue = &the_semaphore->Wait_queue;
+ executing->Wait.id = id;
+ _ISR_Enable( level );
+ _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout );
}