1 | /* |
---|
2 | * Copyright (c) 2014 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #if HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems/rtems/semimpl.h> |
---|
20 | #include <rtems/rtems/attrimpl.h> |
---|
21 | #include <rtems/rtems/tasksimpl.h> |
---|
22 | #include <rtems/score/schedulerimpl.h> |
---|
23 | |
---|
24 | static rtems_status_code _Semaphore_Set_priority( |
---|
25 | Semaphore_Control *the_semaphore, |
---|
26 | rtems_id scheduler_id, |
---|
27 | rtems_task_priority new_priority, |
---|
28 | rtems_task_priority *old_priority_p |
---|
29 | ) |
---|
30 | { |
---|
31 | rtems_status_code sc; |
---|
32 | rtems_attribute attribute_set = the_semaphore->attribute_set; |
---|
33 | rtems_task_priority old_priority; |
---|
34 | |
---|
35 | new_priority = _RTEMS_tasks_Priority_to_Core( new_priority ); |
---|
36 | |
---|
37 | #if defined(RTEMS_SMP) |
---|
38 | if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) { |
---|
39 | MRSP_Control *mrsp = &the_semaphore->Core_control.mrsp; |
---|
40 | uint32_t scheduler_index = _Scheduler_Get_index_by_id( scheduler_id ); |
---|
41 | |
---|
42 | old_priority = _MRSP_Get_ceiling_priority( mrsp, scheduler_index ); |
---|
43 | |
---|
44 | if ( new_priority != RTEMS_CURRENT_PRIORITY ) { |
---|
45 | _MRSP_Set_ceiling_priority( mrsp, scheduler_index, new_priority ); |
---|
46 | } |
---|
47 | |
---|
48 | sc = RTEMS_SUCCESSFUL; |
---|
49 | } else |
---|
50 | #endif |
---|
51 | if ( _Attributes_Is_priority_ceiling( attribute_set ) ) { |
---|
52 | CORE_mutex_Control *mutex = &the_semaphore->Core_control.mutex; |
---|
53 | |
---|
54 | old_priority = mutex->Attributes.priority_ceiling; |
---|
55 | |
---|
56 | if ( new_priority != RTEMS_CURRENT_PRIORITY ) { |
---|
57 | mutex->Attributes.priority_ceiling = new_priority; |
---|
58 | } |
---|
59 | |
---|
60 | sc = RTEMS_SUCCESSFUL; |
---|
61 | } else { |
---|
62 | old_priority = 0; |
---|
63 | |
---|
64 | sc = RTEMS_NOT_DEFINED; |
---|
65 | } |
---|
66 | |
---|
67 | *old_priority_p = _RTEMS_tasks_Priority_from_Core( old_priority ); |
---|
68 | |
---|
69 | _Objects_Put( &the_semaphore->Object ); |
---|
70 | |
---|
71 | return sc; |
---|
72 | } |
---|
73 | |
---|
74 | rtems_status_code rtems_semaphore_set_priority( |
---|
75 | rtems_id semaphore_id, |
---|
76 | rtems_id scheduler_id, |
---|
77 | rtems_task_priority new_priority, |
---|
78 | rtems_task_priority *old_priority |
---|
79 | ) |
---|
80 | { |
---|
81 | Semaphore_Control *the_semaphore; |
---|
82 | Objects_Locations location; |
---|
83 | |
---|
84 | if ( new_priority != RTEMS_CURRENT_PRIORITY && |
---|
85 | !_RTEMS_tasks_Priority_is_valid( new_priority ) ) { |
---|
86 | return RTEMS_INVALID_PRIORITY; |
---|
87 | } |
---|
88 | |
---|
89 | if ( old_priority == NULL ) { |
---|
90 | return RTEMS_INVALID_ADDRESS; |
---|
91 | } |
---|
92 | |
---|
93 | if ( !_Scheduler_Is_id_valid( scheduler_id ) ) { |
---|
94 | return RTEMS_INVALID_ID; |
---|
95 | } |
---|
96 | |
---|
97 | the_semaphore = _Semaphore_Get( semaphore_id, &location ); |
---|
98 | switch ( location ) { |
---|
99 | case OBJECTS_LOCAL: |
---|
100 | return _Semaphore_Set_priority( |
---|
101 | the_semaphore, |
---|
102 | scheduler_id, |
---|
103 | new_priority, |
---|
104 | old_priority |
---|
105 | ); |
---|
106 | #if defined(RTEMS_MULTIPROCESSING) |
---|
107 | case OBJECTS_REMOTE: |
---|
108 | _Thread_Dispatch(); |
---|
109 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
110 | #endif |
---|
111 | case OBJECTS_ERROR: |
---|
112 | break; |
---|
113 | } |
---|
114 | |
---|
115 | return RTEMS_INVALID_ID; |
---|
116 | } |
---|