diff options
Diffstat (limited to 'cpukit/include/rtems/score/coremuteximpl.h')
-rw-r--r-- | cpukit/include/rtems/score/coremuteximpl.h | 150 |
1 files changed, 64 insertions, 86 deletions
diff --git a/cpukit/include/rtems/score/coremuteximpl.h b/cpukit/include/rtems/score/coremuteximpl.h index cbc1e720fb..bcdd1adceb 100644 --- a/cpukit/include/rtems/score/coremuteximpl.h +++ b/cpukit/include/rtems/score/coremuteximpl.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -11,9 +13,26 @@ * COPYRIGHT (c) 1989-2009. * On-Line Applications Research Corporation (OAR). * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _RTEMS_SCORE_COREMUTEXIMPL_H @@ -46,7 +65,7 @@ extern "C" { * * @param[out] the_mutex The mutex to initialize. */ -RTEMS_INLINE_ROUTINE void _CORE_mutex_Initialize( +static inline void _CORE_mutex_Initialize( CORE_mutex_Control *the_mutex ) { @@ -58,7 +77,7 @@ RTEMS_INLINE_ROUTINE void _CORE_mutex_Initialize( * * @param[out] the_mutex the mutex to destroy. */ -RTEMS_INLINE_ROUTINE void _CORE_mutex_Destroy( CORE_mutex_Control *the_mutex ) +static inline void _CORE_mutex_Destroy( CORE_mutex_Control *the_mutex ) { _Thread_queue_Destroy( &the_mutex->Wait_queue ); } @@ -69,7 +88,7 @@ RTEMS_INLINE_ROUTINE void _CORE_mutex_Destroy( CORE_mutex_Control *the_mutex ) * @param[in, out] the_mutex The mutex to acquire critical. * @param queue_context The queue context. */ -RTEMS_INLINE_ROUTINE void _CORE_mutex_Acquire_critical( +static inline void _CORE_mutex_Acquire_critical( CORE_mutex_Control *the_mutex, Thread_queue_Context *queue_context ) @@ -83,7 +102,7 @@ RTEMS_INLINE_ROUTINE void _CORE_mutex_Acquire_critical( * @param[in, out] the_mutex The mutex to release. * @param queue_context The queue context. */ -RTEMS_INLINE_ROUTINE void _CORE_mutex_Release( +static inline void _CORE_mutex_Release( CORE_mutex_Control *the_mutex, Thread_queue_Context *queue_context ) @@ -98,7 +117,7 @@ RTEMS_INLINE_ROUTINE void _CORE_mutex_Release( * * @return The owner of the mutex. */ -RTEMS_INLINE_ROUTINE Thread_Control *_CORE_mutex_Get_owner( +static inline Thread_Control *_CORE_mutex_Get_owner( const CORE_mutex_Control *the_mutex ) { @@ -116,7 +135,7 @@ RTEMS_INLINE_ROUTINE Thread_Control *_CORE_mutex_Get_owner( * @retval true The mutex is locked. * @retval false The mutex is not locked. */ -RTEMS_INLINE_ROUTINE bool _CORE_mutex_Is_locked( +static inline bool _CORE_mutex_Is_locked( const CORE_mutex_Control *the_mutex ) { @@ -149,7 +168,7 @@ Status_Control _CORE_mutex_Seize_slow( * @param[out] the_mutex The mutex to set the owner from. * @param owner The new owner of the mutex. */ -RTEMS_INLINE_ROUTINE void _CORE_mutex_Set_owner( +static inline void _CORE_mutex_Set_owner( CORE_mutex_Control *the_mutex, Thread_Control *owner ) @@ -166,7 +185,7 @@ RTEMS_INLINE_ROUTINE void _CORE_mutex_Set_owner( * @retval true @a the_thread is the owner of @a the_mutex. * @retval false @a the_thread is not the owner of @a the_mutex. */ -RTEMS_INLINE_ROUTINE bool _CORE_mutex_Is_owner( +static inline bool _CORE_mutex_Is_owner( const CORE_mutex_Control *the_mutex, const Thread_Control *the_thread ) @@ -179,7 +198,7 @@ RTEMS_INLINE_ROUTINE bool _CORE_mutex_Is_owner( * * @param[out] the_mutex The recursive mutex to initialize. */ -RTEMS_INLINE_ROUTINE void _CORE_recursive_mutex_Initialize( +static inline void _CORE_recursive_mutex_Initialize( CORE_recursive_mutex_Control *the_mutex ) { @@ -194,7 +213,7 @@ RTEMS_INLINE_ROUTINE void _CORE_recursive_mutex_Initialize( * * @return STATUS_SUCCESSFUL, this method is always successful. */ -RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Seize_nested( +static inline Status_Control _CORE_recursive_mutex_Seize_nested( CORE_recursive_mutex_Control *the_mutex ) { @@ -217,7 +236,7 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Seize_nested( * @retval _Thread_Wait_get_status The status of the executing thread. * @retval STATUS_UNAVAILABLE The calling thread is not willing to wait. */ -RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Seize( +static inline Status_Control _CORE_recursive_mutex_Seize( CORE_recursive_mutex_Control *the_mutex, const Thread_queue_Operations *operations, Thread_Control *executing, @@ -267,7 +286,7 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Seize( * @retval STATUS_SUCCESSFUL @a the_mutex is successfully surrendered. * @retval STATUS_NOT_OWNER The executing thread does not own @a the_mutex. */ -RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Surrender( +static inline Status_Control _CORE_recursive_mutex_Surrender( CORE_recursive_mutex_Control *the_mutex, const Thread_queue_Operations *operations, Thread_Control *executing, @@ -320,7 +339,7 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_recursive_mutex_Surrender( * Only needed if RTEMS_SMP is defined * @param priority_ceiling The priority ceiling for the initialized mutex. */ -RTEMS_INLINE_ROUTINE void _CORE_ceiling_mutex_Initialize( +static inline void _CORE_ceiling_mutex_Initialize( CORE_ceiling_mutex_Control *the_mutex, const Scheduler_Control *scheduler, Priority_Control priority_ceiling @@ -340,7 +359,7 @@ RTEMS_INLINE_ROUTINE void _CORE_ceiling_mutex_Initialize( * * @return The scheduler of the mutex. If RTEMS_SMP is not defined, the first entry of the _Scheduler_Table is returned. */ -RTEMS_INLINE_ROUTINE const Scheduler_Control * +static inline const Scheduler_Control * _CORE_ceiling_mutex_Get_scheduler( const CORE_ceiling_mutex_Control *the_mutex ) @@ -357,12 +376,10 @@ _CORE_ceiling_mutex_Get_scheduler( * * @param[out] the_mutex The ceiling mutex to set the priority of. * @param priority_ceiling The new priority ceiling of the mutex. - * @param queue_context The thread queue context. */ -RTEMS_INLINE_ROUTINE void _CORE_ceiling_mutex_Set_priority( +static inline void _CORE_ceiling_mutex_Set_priority( CORE_ceiling_mutex_Control *the_mutex, - Priority_Control priority_ceiling, - Thread_queue_Context *queue_context + Priority_Control priority_ceiling ) { Thread_Control *owner; @@ -370,15 +387,19 @@ RTEMS_INLINE_ROUTINE void _CORE_ceiling_mutex_Set_priority( owner = _CORE_mutex_Get_owner( &the_mutex->Recursive.Mutex ); if ( owner != NULL ) { - _Thread_Wait_acquire( owner, queue_context ); + Thread_queue_Context queue_context; + + _Thread_queue_Context_initialize( &queue_context ); + _Thread_queue_Context_clear_priority_updates( &queue_context ); + _Thread_Wait_acquire_critical( owner, &queue_context ); _Thread_Priority_change( owner, &the_mutex->Priority_ceiling, priority_ceiling, - false, - queue_context + PRIORITY_GROUP_LAST, + &queue_context ); - _Thread_Wait_release( owner, queue_context ); + _Thread_Wait_release_critical( owner, &queue_context ); } else { the_mutex->Priority_ceiling.priority = priority_ceiling; } @@ -391,7 +412,7 @@ RTEMS_INLINE_ROUTINE void _CORE_ceiling_mutex_Set_priority( * * @return The priority ceiling of @a the_mutex. */ -RTEMS_INLINE_ROUTINE Priority_Control _CORE_ceiling_mutex_Get_priority( +static inline Priority_Control _CORE_ceiling_mutex_Get_priority( const CORE_ceiling_mutex_Control *the_mutex ) { @@ -409,7 +430,7 @@ RTEMS_INLINE_ROUTINE Priority_Control _CORE_ceiling_mutex_Get_priority( * @retval STATUS_MUTEX_CEILING_VIOLATED The owners wait priority * is smaller than the priority of the ceiling mutex. */ -RTEMS_INLINE_ROUTINE Status_Control _CORE_ceiling_mutex_Set_owner( +static inline Status_Control _CORE_ceiling_mutex_Set_owner( CORE_ceiling_mutex_Control *the_mutex, Thread_Control *owner, Thread_queue_Context *queue_context @@ -463,7 +484,7 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_ceiling_mutex_Set_owner( * is smaller than the priority of the ceiling mutex. * @retval other Return value of @a nested. */ -RTEMS_INLINE_ROUTINE Status_Control _CORE_ceiling_mutex_Seize( +static inline Status_Control _CORE_ceiling_mutex_Seize( CORE_ceiling_mutex_Control *the_mutex, Thread_Control *executing, bool wait, @@ -475,19 +496,19 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_ceiling_mutex_Seize( _CORE_mutex_Acquire_critical( &the_mutex->Recursive.Mutex, queue_context ); - owner = _CORE_mutex_Get_owner( &the_mutex->Recursive.Mutex ); - - if ( owner == NULL ) { #if defined(RTEMS_SMP) - if ( - _Thread_Scheduler_get_home( executing ) - != _CORE_ceiling_mutex_Get_scheduler( the_mutex ) - ) { - _CORE_mutex_Release( &the_mutex->Recursive.Mutex, queue_context ); - return STATUS_NOT_DEFINED; - } + if ( + _Thread_Scheduler_get_home( executing ) + != _CORE_ceiling_mutex_Get_scheduler( the_mutex ) + ) { + _CORE_mutex_Release( &the_mutex->Recursive.Mutex, queue_context ); + return STATUS_NOT_DEFINED; + } #endif + owner = _CORE_mutex_Get_owner( &the_mutex->Recursive.Mutex ); + + if ( owner == NULL ) { _Thread_queue_Context_clear_priority_updates( queue_context ); return _CORE_ceiling_mutex_Set_owner( the_mutex, @@ -523,16 +544,13 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_ceiling_mutex_Seize( * @retval STATUS_SUCCESSFUL The ceiling mutex was successfullysurrendered. * @retval STATUS_NOT_OWNER The executing thread is not the owner of @a the_mutex. */ -RTEMS_INLINE_ROUTINE Status_Control _CORE_ceiling_mutex_Surrender( +static inline Status_Control _CORE_ceiling_mutex_Surrender( CORE_ceiling_mutex_Control *the_mutex, Thread_Control *executing, Thread_queue_Context *queue_context ) { - unsigned int nest_level; - ISR_lock_Context lock_context; - Per_CPU_Control *cpu_self; - Thread_Control *new_owner; + unsigned int nest_level; _CORE_mutex_Acquire_critical( &the_mutex->Recursive.Mutex, queue_context ); @@ -549,53 +567,13 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_ceiling_mutex_Surrender( return STATUS_SUCCESSFUL; } - _Thread_Resource_count_decrement( executing ); - - _Thread_queue_Context_clear_priority_updates( queue_context ); - _Thread_Wait_acquire_default_critical( executing, &lock_context ); - _Thread_Priority_remove( + return _Thread_queue_Surrender_priority_ceiling( + &the_mutex->Recursive.Mutex.Wait_queue.Queue, executing, &the_mutex->Priority_ceiling, - queue_context - ); - _Thread_Wait_release_default_critical( executing, &lock_context ); - - new_owner = _Thread_queue_First_locked( - &the_mutex->Recursive.Mutex.Wait_queue, + queue_context, CORE_MUTEX_TQ_OPERATIONS ); - _CORE_mutex_Set_owner( &the_mutex->Recursive.Mutex, new_owner ); - - cpu_self = _Thread_Dispatch_disable_critical( - &queue_context->Lock_context.Lock_context - ); - - if ( new_owner != NULL ) { -#if defined(RTEMS_MULTIPROCESSING) - if ( _Objects_Is_local_id( new_owner->Object.id ) ) -#endif - { - _Thread_Resource_count_increment( new_owner ); - _Thread_Priority_add( - new_owner, - &the_mutex->Priority_ceiling, - queue_context - ); - } - - _Thread_queue_Extract_critical( - &the_mutex->Recursive.Mutex.Wait_queue.Queue, - CORE_MUTEX_TQ_OPERATIONS, - new_owner, - queue_context - ); - } else { - _CORE_mutex_Release( &the_mutex->Recursive.Mutex, queue_context ); - } - - _Thread_Priority_update( queue_context ); - _Thread_Dispatch_enable( cpu_self ); - return STATUS_SUCCESSFUL; } /** @} */ |