diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-06-22 17:09:23 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-09-21 08:59:26 +0200 |
commit | 300f6a481aaf9e6d29811faca71bf7104a01492c (patch) | |
tree | ba8f18cedb93e3781a2f17aa989c5c805dd18d6a /cpukit/posix/src/pthreadsetschedprio.c | |
parent | classic networking: do not reference BSP_irq_enabled_at_i8259s which is no mo... (diff) | |
download | rtems-300f6a481aaf9e6d29811faca71bf7104a01492c.tar.bz2 |
score: Rework thread priority management
Add priority nodes which contribute to the overall thread priority.
The actual priority of a thread is now an aggregation of priority nodes.
The thread priority aggregation for the home scheduler instance of a
thread consists of at least one priority node, which is normally the
real priority of the thread. The locking protocols (e.g. priority
ceiling and priority inheritance), rate-monotonic period objects and the
POSIX sporadic server add, change and remove priority nodes.
A thread changes its priority now immediately, e.g. priority changes are
not deferred until the thread releases its last resource.
Replace the _Thread_Change_priority() function with
* _Thread_Priority_perform_actions(),
* _Thread_Priority_add(),
* _Thread_Priority_remove(),
* _Thread_Priority_change(), and
* _Thread_Priority_update().
Update #2412.
Update #2556.
Diffstat (limited to '')
-rw-r--r-- | cpukit/posix/src/pthreadsetschedprio.c | 92 |
1 files changed, 30 insertions, 62 deletions
diff --git a/cpukit/posix/src/pthreadsetschedprio.c b/cpukit/posix/src/pthreadsetschedprio.c index fac86d2609..e3d9de0136 100644 --- a/cpukit/posix/src/pthreadsetschedprio.c +++ b/cpukit/posix/src/pthreadsetschedprio.c @@ -18,79 +18,47 @@ #include <rtems/score/threadimpl.h> #include <rtems/score/schedulerimpl.h> -typedef struct { - int prio; - int error; -} POSIX_Set_sched_prio_context; - -static bool _POSIX_Set_sched_prio_filter( - Thread_Control *the_thread, - Priority_Control *new_priority_p, - void *arg -) -{ - POSIX_Set_sched_prio_context *context; - int prio; - const Scheduler_Control *scheduler; - POSIX_API_Control *api; - bool valid; - Priority_Control current_priority; - Priority_Control new_priority; - - context = arg; - prio = context->prio; - scheduler = _Scheduler_Get_own( the_thread ); - - new_priority = _POSIX_Priority_To_core( scheduler, prio, &valid ); - if ( !valid ) { - context->error = EINVAL; - return false; - } - - *new_priority_p = new_priority; - - current_priority = _Thread_Get_priority( the_thread ); - the_thread->real_priority = new_priority; - - api = the_thread->API_Extensions[ THREAD_API_POSIX ]; - - api->Sporadic.high_priority = new_priority; - - if ( api->Sporadic.low_priority < new_priority ) { - api->Sporadic.low_priority = new_priority; - } - - context->error = 0; - return _Thread_Priority_less_than( current_priority, new_priority ) - || !_Thread_Owns_resources( the_thread ); -} - int pthread_setschedprio( pthread_t thread, int prio ) { - Thread_Control *the_thread; - Per_CPU_Control *cpu_self; - POSIX_Set_sched_prio_context context; - ISR_lock_Context lock_context; - - context.prio = prio; + Thread_Control *the_thread; + Per_CPU_Control *cpu_self; + Thread_queue_Context queue_context; + const Scheduler_Control *scheduler; + Priority_Control new_priority; + bool valid; - the_thread = _Thread_Get( thread, &lock_context ); + the_thread = _Thread_Get( thread, &queue_context.Lock_context.Lock_context ); if ( the_thread == NULL ) { return ESRCH; } - cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); - _ISR_lock_ISR_enable( &lock_context ); + _Thread_queue_Context_clear_priority_updates( &queue_context ); + _Thread_Wait_acquire_critical( the_thread, &queue_context ); - _Thread_Change_priority( + scheduler = _Scheduler_Get_own( the_thread ); + + new_priority = _POSIX_Priority_To_core( scheduler, prio, &valid ); + if ( !valid ) { + _Thread_Wait_release( the_thread, &queue_context ); + return EINVAL; + } + + _Thread_Priority_change( the_thread, - 0, - &context, - _POSIX_Set_sched_prio_filter, - true + &the_thread->Real_priority, + new_priority, + true, + &queue_context ); + cpu_self = _Thread_Dispatch_disable_critical( + &queue_context.Lock_context.Lock_context + ); + _Thread_Wait_release( the_thread, &queue_context ); + + _Thread_Priority_update( &queue_context ); + _Thread_Dispatch_enable( cpu_self ); - return context.error; + return 0; } |