diff options
Diffstat (limited to 'cpukit/score/src/corerwlockobtainwrite.c')
-rw-r--r-- | cpukit/score/src/corerwlockobtainwrite.c | 78 |
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 + ); } |