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/src/coresemseize.c | |
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/src/coresemseize.c')
-rw-r--r-- | cpukit/score/src/coresemseize.c | 43 |
1 files changed, 13 insertions, 30 deletions
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 ); } |