From f27383a518836881b7b9b88e88d2e31d5b23d048 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 20 Apr 2016 14:01:02 +0200 Subject: score: Avoid Giant lock for barriers Use _Thread_queue_Flush_critical() to atomically release the barrier. Update #2555. --- cpukit/score/src/corebarrierrelease.c | 36 +++++++++--------------- cpukit/score/src/corebarrierwait.c | 53 ++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 49 deletions(-) (limited to 'cpukit/score/src') diff --git a/cpukit/score/src/corebarrierrelease.c b/cpukit/score/src/corebarrierrelease.c index 6d72203e7e..e6ef335abc 100644 --- a/cpukit/score/src/corebarrierrelease.c +++ b/cpukit/score/src/corebarrierrelease.c @@ -20,34 +20,24 @@ #endif #include -#include -#include uint32_t _CORE_barrier_Do_surrender( - CORE_barrier_Control *the_barrier + CORE_barrier_Control *the_barrier, + Thread_queue_Flush_filter filter, #if defined(RTEMS_MULTIPROCESSING) - , - Thread_queue_MP_callout mp_callout, - Objects_Id mp_id + Thread_queue_MP_callout mp_callout, + Objects_Id mp_id, #endif + ISR_lock_Context *lock_context ) { - Thread_Control *the_thread; - uint32_t count; - - count = 0; - while ( - ( - the_thread = _Thread_queue_Dequeue( - &the_barrier->Wait_queue, - CORE_BARRIER_TQ_OPERATIONS, - mp_callout, - mp_id - ) - ) - ) { - count++; - } the_barrier->number_of_waiting_threads = 0; - return count; + return _Thread_queue_Flush_critical( + &the_barrier->Wait_queue.Queue, + CORE_BARRIER_TQ_OPERATIONS, + filter, + mp_callout, + mp_id, + lock_context + ); } 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 -#include #include -#include 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 + ); + } } -- cgit v1.2.3