diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-20 14:01:02 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-22 09:25:09 +0200 |
commit | f27383a518836881b7b9b88e88d2e31d5b23d048 (patch) | |
tree | ecdccfa9c902a5a8db0918026e8074af0b581a6a /cpukit/score/src/corebarrierwait.c | |
parent | score: Add _Thread_queue_Flush_default_filter() (diff) | |
download | rtems-f27383a518836881b7b9b88e88d2e31d5b23d048.tar.bz2 |
score: Avoid Giant lock for barriers
Use _Thread_queue_Flush_critical() to atomically release the barrier.
Update #2555.
Diffstat (limited to 'cpukit/score/src/corebarrierwait.c')
-rw-r--r-- | cpukit/score/src/corebarrierwait.c | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/cpukit/score/src/corebarrierwait.c b/cpukit/score/src/corebarrierwait.c index 11495e5e69..4a924b28dd 100644 --- a/cpukit/score/src/corebarrierwait.c +++ b/cpukit/score/src/corebarrierwait.c @@ -19,44 +19,45 @@ #endif #include <rtems/score/corebarrierimpl.h> -#include <rtems/score/isrlevel.h> #include <rtems/score/statesimpl.h> -#include <rtems/score/threadqimpl.h> void _CORE_barrier_Do_seize( CORE_barrier_Control *the_barrier, Thread_Control *executing, bool wait, - Watchdog_Interval timeout + Watchdog_Interval timeout, #if defined(RTEMS_MULTIPROCESSING) - , Thread_queue_MP_callout mp_callout, - Objects_Id mp_id + Objects_Id mp_id, #endif + ISR_lock_Context *lock_context ) { - ISR_lock_Context lock_context; + uint32_t number_of_waiting_threads; executing->Wait.return_code = CORE_BARRIER_STATUS_SUCCESSFUL; - _Thread_queue_Acquire( &the_barrier->Wait_queue, &lock_context ); - the_barrier->number_of_waiting_threads++; - if ( _CORE_barrier_Is_automatic( &the_barrier->Attributes ) ) { - if ( the_barrier->number_of_waiting_threads == - the_barrier->Attributes.maximum_count) { - executing->Wait.return_code = CORE_BARRIER_STATUS_AUTOMATICALLY_RELEASED; - _Thread_queue_Release( &the_barrier->Wait_queue, &lock_context ); - _CORE_barrier_Surrender( the_barrier, mp_callout, mp_id ); - return; - } - } - _Thread_queue_Enqueue_critical( - &the_barrier->Wait_queue.Queue, - CORE_BARRIER_TQ_OPERATIONS, - executing, - STATES_WAITING_FOR_BARRIER, - timeout, - CORE_BARRIER_TIMEOUT, - &lock_context - ); + _CORE_barrier_Acquire_critical( the_barrier, lock_context ); + + number_of_waiting_threads = the_barrier->number_of_waiting_threads; + ++number_of_waiting_threads; + + if ( + _CORE_barrier_Is_automatic( &the_barrier->Attributes ) + && number_of_waiting_threads == the_barrier->Attributes.maximum_count + ) { + executing->Wait.return_code = CORE_BARRIER_STATUS_AUTOMATICALLY_RELEASED; + _CORE_barrier_Surrender( the_barrier, mp_callout, mp_id, lock_context ); + } else { + the_barrier->number_of_waiting_threads = number_of_waiting_threads; + _Thread_queue_Enqueue_critical( + &the_barrier->Wait_queue.Queue, + CORE_BARRIER_TQ_OPERATIONS, + executing, + STATES_WAITING_FOR_BARRIER, + timeout, + CORE_BARRIER_TIMEOUT, + lock_context + ); + } } |