summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/corerwlockobtainread.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-04-21 06:32:16 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-04-22 09:25:09 +0200
commit84a539885335c629100a6a12b57ead54bbbc0165 (patch)
treeff8d0acd9624e3888dc7fc6df9003a98a19b9b3d /cpukit/score/src/corerwlockobtainread.c
parentscore: Avoid Giant lock for barriers (diff)
downloadrtems-84a539885335c629100a6a12b57ead54bbbc0165.tar.bz2
score: Avoid Giant lock for CORE rwlock
Update #2555.
Diffstat (limited to 'cpukit/score/src/corerwlockobtainread.c')
-rw-r--r--cpukit/score/src/corerwlockobtainread.c98
1 files changed, 48 insertions, 50 deletions
diff --git a/cpukit/score/src/corerwlockobtainread.c b/cpukit/score/src/corerwlockobtainread.c
index 3d3757144f..fcbaf4a829 100644
--- a/cpukit/score/src/corerwlockobtainread.c
+++ b/cpukit/score/src/corerwlockobtainread.c
@@ -27,70 +27,68 @@ void _CORE_RWLock_Seize_for_reading(
CORE_RWLock_Control *the_rwlock,
Thread_Control *executing,
bool wait,
- Watchdog_Interval timeout
+ Watchdog_Interval timeout,
+ ISR_lock_Context *lock_context
)
{
- ISR_lock_Context lock_context;
-
/*
* If unlocked, then OK to read.
* If locked for reading and no waiters, then OK to read.
* If any thread is waiting, then we wait.
*/
- _Thread_queue_Acquire( &the_rwlock->Wait_queue, &lock_context );
- switch ( the_rwlock->current_state ) {
- case CORE_RWLOCK_UNLOCKED:
- the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_READING;
- the_rwlock->number_of_readers += 1;
- _Thread_queue_Release( &the_rwlock->Wait_queue, &lock_context );
- executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
- return;
+ _CORE_RWLock_Acquire_critical( the_rwlock, lock_context );
+
+ switch ( the_rwlock->current_state ) {
+ case CORE_RWLOCK_UNLOCKED:
+ the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_READING;
+ the_rwlock->number_of_readers += 1;
+ _CORE_RWLock_Release( the_rwlock, lock_context );
+ executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
+ return;
- case CORE_RWLOCK_LOCKED_FOR_READING: {
- Thread_Control *waiter;
- waiter = _Thread_queue_First_locked(
- &the_rwlock->Wait_queue,
- CORE_RWLOCK_TQ_OPERATIONS
- );
- if ( !waiter ) {
- the_rwlock->number_of_readers += 1;
- _Thread_queue_Release( &the_rwlock->Wait_queue, &lock_context );
- executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
- return;
- }
- break;
+ case CORE_RWLOCK_LOCKED_FOR_READING: {
+ Thread_Control *waiter;
+ waiter = _Thread_queue_First_locked(
+ &the_rwlock->Wait_queue,
+ CORE_RWLOCK_TQ_OPERATIONS
+ );
+ if ( !waiter ) {
+ the_rwlock->number_of_readers += 1;
+ _CORE_RWLock_Release( the_rwlock, lock_context );
+ executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
+ return;
}
- case CORE_RWLOCK_LOCKED_FOR_WRITING:
- break;
+ break;
}
+ case CORE_RWLOCK_LOCKED_FOR_WRITING:
+ break;
+ }
- /*
- * If the thread is not willing to wait, then return immediately.
- */
-
- if ( !wait ) {
- _Thread_queue_Release( &the_rwlock->Wait_queue, &lock_context );
- executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE;
- return;
- }
+ /*
+ * If the thread is not willing to wait, then return immediately.
+ */
- /*
- * We need to wait to enter this critical section
- */
+ if ( !wait ) {
+ _CORE_RWLock_Release( the_rwlock, lock_context );
+ executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE;
+ return;
+ }
- executing->Wait.option = CORE_RWLOCK_THREAD_WAITING_FOR_READ;
- executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
+ /*
+ * We need to wait to enter this critical section
+ */
- _Thread_queue_Enqueue_critical(
- &the_rwlock->Wait_queue.Queue,
- CORE_RWLOCK_TQ_OPERATIONS,
- executing,
- STATES_WAITING_FOR_RWLOCK,
- timeout,
- CORE_RWLOCK_TIMEOUT,
- &lock_context
- );
+ executing->Wait.option = CORE_RWLOCK_THREAD_WAITING_FOR_READ;
+ executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
- /* return to API level so it can dispatch and we block */
+ _Thread_queue_Enqueue_critical(
+ &the_rwlock->Wait_queue.Queue,
+ CORE_RWLOCK_TQ_OPERATIONS,
+ executing,
+ STATES_WAITING_FOR_RWLOCK,
+ timeout,
+ CORE_RWLOCK_TIMEOUT,
+ lock_context
+ );
}