summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/corerwlockobtainwrite.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/corerwlockobtainwrite.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/corerwlockobtainwrite.c')
-rw-r--r--cpukit/score/src/corerwlockobtainwrite.c78
1 files changed, 38 insertions, 40 deletions
diff --git a/cpukit/score/src/corerwlockobtainwrite.c b/cpukit/score/src/corerwlockobtainwrite.c
index 07fe03acaa..e1bb1bd14a 100644
--- a/cpukit/score/src/corerwlockobtainwrite.c
+++ b/cpukit/score/src/corerwlockobtainwrite.c
@@ -24,14 +24,13 @@
#include <rtems/score/watchdog.h>
void _CORE_RWLock_Seize_for_writing(
- CORE_RWLock_Control *the_rwlock,
- Thread_Control *executing,
- bool wait,
- Watchdog_Interval timeout
+ CORE_RWLock_Control *the_rwlock,
+ Thread_Control *executing,
+ bool wait,
+ Watchdog_Interval timeout,
+ ISR_lock_Context *lock_context
)
{
- ISR_lock_Context lock_context;
-
/*
* If unlocked, then OK to read.
* Otherwise, we have to block.
@@ -39,45 +38,44 @@ void _CORE_RWLock_Seize_for_writing(
* 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_WRITING;
- _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 );
- case CORE_RWLOCK_LOCKED_FOR_READING:
- case CORE_RWLOCK_LOCKED_FOR_WRITING:
- break;
- }
+ switch ( the_rwlock->current_state ) {
+ case CORE_RWLOCK_UNLOCKED:
+ the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_WRITING;
+ _CORE_RWLock_Release( the_rwlock, lock_context );
+ executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
+ return;
- /*
- * If the thread is not willing to wait, then return immediately.
- */
+ case CORE_RWLOCK_LOCKED_FOR_READING:
+ case CORE_RWLOCK_LOCKED_FOR_WRITING:
+ break;
+ }
- 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_WRITE;
- 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_WRITE;
+ 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
+ );
}