summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/pthreadsetschedprio.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/posix/src/pthreadsetschedprio.c')
-rw-r--r--cpukit/posix/src/pthreadsetschedprio.c92
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;
}