1 | /* |
---|
2 | * Copyright (c) 2016 embedded brains GmbH |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.org/license/LICENSE. |
---|
7 | */ |
---|
8 | |
---|
9 | #if HAVE_CONFIG_H |
---|
10 | #include "config.h" |
---|
11 | #endif |
---|
12 | |
---|
13 | #include <pthread.h> |
---|
14 | #include <errno.h> |
---|
15 | |
---|
16 | #include <rtems/posix/priorityimpl.h> |
---|
17 | #include <rtems/posix/threadsup.h> |
---|
18 | #include <rtems/score/threadimpl.h> |
---|
19 | #include <rtems/score/schedulerimpl.h> |
---|
20 | |
---|
21 | int pthread_setschedprio( pthread_t thread, int prio ) |
---|
22 | { |
---|
23 | Thread_Control *the_thread; |
---|
24 | Per_CPU_Control *cpu_self; |
---|
25 | Thread_queue_Context queue_context; |
---|
26 | const Scheduler_Control *scheduler; |
---|
27 | Priority_Control new_priority; |
---|
28 | bool valid; |
---|
29 | |
---|
30 | _Thread_queue_Context_initialize( &queue_context ); |
---|
31 | _Thread_queue_Context_clear_priority_updates( &queue_context ); |
---|
32 | the_thread = _Thread_Get( thread, &queue_context.Lock_context.Lock_context ); |
---|
33 | |
---|
34 | if ( the_thread == NULL ) { |
---|
35 | return ESRCH; |
---|
36 | } |
---|
37 | |
---|
38 | _Thread_Wait_acquire_critical( the_thread, &queue_context ); |
---|
39 | |
---|
40 | scheduler = _Thread_Scheduler_get_home( the_thread ); |
---|
41 | |
---|
42 | new_priority = _POSIX_Priority_To_core( scheduler, prio, &valid ); |
---|
43 | if ( !valid ) { |
---|
44 | _Thread_Wait_release( the_thread, &queue_context ); |
---|
45 | return EINVAL; |
---|
46 | } |
---|
47 | |
---|
48 | _Thread_Priority_change( |
---|
49 | the_thread, |
---|
50 | &the_thread->Real_priority, |
---|
51 | new_priority, |
---|
52 | true, |
---|
53 | &queue_context |
---|
54 | ); |
---|
55 | |
---|
56 | cpu_self = _Thread_queue_Dispatch_disable( &queue_context ); |
---|
57 | _Thread_Wait_release( the_thread, &queue_context ); |
---|
58 | |
---|
59 | _Thread_Priority_update( &queue_context ); |
---|
60 | |
---|
61 | _Thread_Dispatch_enable( cpu_self ); |
---|
62 | return 0; |
---|
63 | } |
---|