summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/corerwlockrelease.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2006-12-04 14:16:26 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2006-12-04 14:16:26 +0000
commit6bc7a5e1a38d6566fb404bcb736bf96926f4b1fe (patch)
treeb1391462c49d831b954c61d2712228fa7b87ddc0 /cpukit/score/src/corerwlockrelease.c
parent2006-12-04 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-6bc7a5e1a38d6566fb404bcb736bf96926f4b1fe.tar.bz2
2006-12-04 Joel Sherrill <joel.sherrill@oarcorp.com>
* posix/src/prwlockunlock.c, rtems/Makefile.am, rtems/src/barrierrelease.c, rtems/src/barrierwait.c, score/src/corerwlockobtainread.c, score/src/corerwlockrelease.c: Complete implementation of barrier as the rest of the test code is now implemented. Also add blocking code to rwlock.
Diffstat (limited to 'cpukit/score/src/corerwlockrelease.c')
-rw-r--r--cpukit/score/src/corerwlockrelease.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/cpukit/score/src/corerwlockrelease.c b/cpukit/score/src/corerwlockrelease.c
index 5943785664..30daaeaba9 100644
--- a/cpukit/score/src/corerwlockrelease.c
+++ b/cpukit/score/src/corerwlockrelease.c
@@ -39,6 +39,8 @@ CORE_RWLock_Status _CORE_RWLock_Release(
{
ISR_Level level;
Thread_Control *executing = _Thread_Executing;
+ Thread_Control *next;
+ uint32_t rwmode;
/*
* If unlocked, then OK to read.
@@ -64,6 +66,7 @@ CORE_RWLock_Status _CORE_RWLock_Release(
executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
break;
case CORE_RWLOCK_LOCKED_FOR_WRITING:
+ executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
break;
}
@@ -71,10 +74,37 @@ CORE_RWLock_Status _CORE_RWLock_Release(
* Implicitly transition to "unlocked" and find another thread interested
* in obtaining this rwlock.
*/
+ the_rwlock->current_state = CORE_RWLOCK_UNLOCKED;
+ _ISR_Enable( level );
+
+ next = _Thread_queue_Dequeue( &the_rwlock->Wait_queue );
+
+ rwmode = next->Wait.option;
+ if ( rwmode == CORE_RWLOCK_THREAD_WAITING_FOR_WRITE ) {
+ the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_WRITING;
+ return CORE_RWLOCK_SUCCESSFUL;
+ }
+
+ /*
+ * Must be CORE_RWLOCK_THREAD_WAITING_FOR_READING now see if more
+ * readers can be let go.
+ */
+
+ while ( 1 ) {
+ next = _Thread_queue_First( &the_rwlock->Wait_queue );
+ if ( !next )
+ return CORE_RWLOCK_SUCCESSFUL;
+ if ( next->Wait.option != CORE_RWLOCK_THREAD_WAITING_FOR_READ )
+ return CORE_RWLOCK_SUCCESSFUL;
+
+ /* it is definitely wanting to read */
+ the_rwlock->number_of_readers += 1;
+ _Thread_queue_Extract( &the_rwlock->Wait_queue, next );
+ }
+
+
/* XXX need to put read/write lock request indicator in Wait info */
- /* XXX find one writer or multiple readers to take off */
- _ISR_Enable( level );
return CORE_RWLOCK_SUCCESSFUL;
}