From f4d1f307926b6319e5d3b325dbe424901285dec1 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 22 Jun 2016 17:09:56 +0200 Subject: score: Split _Thread_Change_priority() Update #2412. Update #2556. Update #2765. --- cpukit/score/include/rtems/score/threadimpl.h | 10 +++++ cpukit/score/src/threadchangepriority.c | 61 +++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h index ec82b917e9..5323e2c85b 100644 --- a/cpukit/score/include/rtems/score/threadimpl.h +++ b/cpukit/score/include/rtems/score/threadimpl.h @@ -460,6 +460,16 @@ typedef bool ( *Thread_Change_priority_filter )( void *arg ); +Thread_Control *_Thread_Apply_priority( + Thread_Control *the_thread, + Priority_Control new_priority, + void *arg, + Thread_Change_priority_filter filter, + bool prepend_it +); + +void _Thread_Update_priority( Thread_Control *the_thread ); + /** * @brief Changes the priority of a thread if allowed by the filter function. * diff --git a/cpukit/score/src/threadchangepriority.c b/cpukit/score/src/threadchangepriority.c index 7b22371326..d895ee6dbe 100644 --- a/cpukit/score/src/threadchangepriority.c +++ b/cpukit/score/src/threadchangepriority.c @@ -22,7 +22,7 @@ #include #include -void _Thread_Change_priority( +static Thread_Control *_Thread_Apply_priority_locked( Thread_Control *the_thread, Priority_Control new_priority, void *arg, @@ -30,11 +30,6 @@ void _Thread_Change_priority( bool prepend_it ) { - ISR_lock_Context lock_context; - ISR_lock_Control *lock; - - lock = _Thread_Lock_acquire( the_thread, &lock_context ); - /* * For simplicity set the priority restore hint unconditionally since this is * an average case optimization. Otherwise complicated atomic operations @@ -62,17 +57,65 @@ void _Thread_Change_priority( new_priority, the_thread->Wait.queue ); + } else { + the_thread = NULL; + } - _Thread_Lock_release( lock, &lock_context ); + return the_thread; +} + +Thread_Control *_Thread_Apply_priority( + Thread_Control *the_thread, + Priority_Control new_priority, + void *arg, + Thread_Change_priority_filter filter, + bool prepend_it +) +{ + ISR_lock_Context lock_context; + ISR_lock_Control *lock; + + lock = _Thread_Lock_acquire( the_thread, &lock_context ); + the_thread = _Thread_Apply_priority_locked( + the_thread, + new_priority, + arg, + filter, + prepend_it + ); + _Thread_Lock_release( lock, &lock_context ); + return the_thread; +} + +void _Thread_Update_priority( Thread_Control *the_thread ) +{ + if ( the_thread != NULL ) { + ISR_lock_Context lock_context; _Thread_State_acquire( the_thread, &lock_context ); _Scheduler_Update_priority( the_thread ); _Thread_State_release( the_thread, &lock_context ); - } else { - _Thread_Lock_release( lock, &lock_context ); } } +void _Thread_Change_priority( + Thread_Control *the_thread, + Priority_Control new_priority, + void *arg, + Thread_Change_priority_filter filter, + bool prepend_it +) +{ + the_thread = _Thread_Apply_priority( + the_thread, + new_priority, + arg, + filter, + prepend_it + ); + _Thread_Update_priority( the_thread ); +} + static bool _Thread_Raise_priority_filter( Thread_Control *the_thread, Priority_Control *new_priority, -- cgit v1.2.3