diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-07-18 18:45:56 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-07-18 18:45:56 +0000 |
commit | 6a0898bba30ccd936e0ac1d6268970316efe92c4 (patch) | |
tree | 364d967bdfcdb75695666e37263cb2f0bed3a077 /cpukit/score | |
parent | Changed special purpose register inline functions to macros. (diff) | |
download | rtems-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/score')
-rw-r--r-- | cpukit/score/include/rtems/score/coremutex.h | 2 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/coresem.h | 42 | ||||
-rw-r--r-- | cpukit/score/src/coresemseize.c | 43 |
3 files changed, 22 insertions, 65 deletions
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 ); } |