From f5d4570fe699f9930a23199ca0e9f45b5fa4a219 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Sat, 11 Jul 2015 21:14:46 +0200 Subject: score: Simplify _Thread_Lock_set() Exploit the fact that the current thread lock must be the default thread lock and interrupts are disabled if we call _Thread_Lock_set(). --- cpukit/score/include/rtems/score/threadimpl.h | 67 ++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h index ffff220288..0dfdb8a263 100644 --- a/cpukit/score/include/rtems/score/threadimpl.h +++ b/cpukit/score/include/rtems/score/threadimpl.h @@ -1009,22 +1009,25 @@ RTEMS_INLINE_ROUTINE void _Thread_Lock_acquire_default( } /** - * @brief Release the default thread lock. + * @brief Releases the thread lock inside a critical section (interrupts + * disabled). * - * @param[in] the_thread The thread. + * The previous interrupt status is not restored. + * + * @param[in] lock The lock. * @param[in] lock_context The lock context used for the corresponding lock * acquire. */ -RTEMS_INLINE_ROUTINE void _Thread_Lock_release_default( - Thread_Control *the_thread, +RTEMS_INLINE_ROUTINE void _Thread_Lock_release_critical( + ISR_lock_Control *lock, ISR_lock_Context *lock_context ) { - _ISR_lock_Release_and_ISR_enable( &the_thread->Lock.Default, lock_context ); + _ISR_lock_Release( lock, lock_context ); } /** - * @brief Release the thread lock. + * @brief Releases the thread lock. * * @param[in] lock The lock returned by _Thread_Lock_acquire(). * @param[in] lock_context The lock context used for _Thread_Lock_acquire(). @@ -1034,7 +1037,49 @@ RTEMS_INLINE_ROUTINE void _Thread_Lock_release( ISR_lock_Context *lock_context ) { - _ISR_lock_Release_and_ISR_enable( lock, lock_context ); + _Thread_Lock_release_critical( lock, lock_context ); + _ISR_lock_ISR_enable( lock_context ); +} + +/** + * @brief Releases the default thread lock inside a critical section + * (interrupts disabled). + * + * The previous interrupt status is not restored. + * + * @param[in] the_thread The thread. + * @param[in] lock_context The lock context used for the corresponding lock + * acquire. + */ +RTEMS_INLINE_ROUTINE void _Thread_Lock_release_default_critical( + Thread_Control *the_thread, + ISR_lock_Context *lock_context +) +{ + _Thread_Lock_release_critical( +#if defined(RTEMS_SMP) + &the_thread->Lock.Default, +#else + NULL, +#endif + lock_context + ); +} + +/** + * @brief Releases the default thread lock. + * + * @param[in] the_thread The thread. + * @param[in] lock_context The lock context used for the corresponding lock + * acquire. + */ +RTEMS_INLINE_ROUTINE void _Thread_Lock_release_default( + Thread_Control *the_thread, + ISR_lock_Context *lock_context +) +{ + _Thread_Lock_release_default_critical( the_thread, lock_context ); + _ISR_lock_ISR_enable( lock_context ); } /** @@ -1135,12 +1180,12 @@ RTEMS_INLINE_ROUTINE void _Thread_Lock_set( ISR_lock_Control *new_lock ) { - ISR_lock_Control *lock; - ISR_lock_Context lock_context; + ISR_lock_Context lock_context; - lock = _Thread_Lock_acquire( the_thread, &lock_context ); + _Thread_Lock_acquire_default_critical( the_thread, &lock_context ); + _Assert( the_thread->Lock.current == &the_thread->Lock.Default ); _Thread_Lock_set_unprotected( the_thread, new_lock ); - _Thread_Lock_release( lock, &lock_context ); + _Thread_Lock_release_default_critical( the_thread, &lock_context ); } #else #define _Thread_Lock_set( the_thread, new_lock ) \ -- cgit v1.2.3