@@ -180,7 +180,7 @@ rt_err_t rt_sched_tick_increase(rt_tick_t tick)
180
180
/**
181
181
* @brief Update priority of the target thread
182
182
*/
183
- rt_err_t rt_sched_thread_change_priority (struct rt_thread * thread , rt_uint8_t priority )
183
+ rt_err_t rt_sched_thread_change_curr_priority (struct rt_thread * thread , rt_uint8_t priority )
184
184
{
185
185
RT_ASSERT (priority < RT_THREAD_PRIORITY_MAX );
186
186
RT_SCHED_DEBUG_IS_LOCKED ;
@@ -224,6 +224,60 @@ rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t pr
224
224
return RT_EOK ;
225
225
}
226
226
227
+ /**
228
+ * @brief Update priority of the target thread
229
+ */
230
+ rt_err_t rt_sched_thread_change_priority (struct rt_thread * thread , rt_uint8_t priority )
231
+ {
232
+ RT_ASSERT (priority < RT_THREAD_PRIORITY_MAX );
233
+ RT_SCHED_DEBUG_IS_LOCKED ;
234
+
235
+ /* change thread init priority */
236
+ RT_SCHED_PRIV (thread ).init_priority = priority ;
237
+
238
+ /* if this thread takes mutex, its current prio is controlled by mutex */
239
+ if (rt_list_isempty (& thread -> taken_object_list ) && (rt_object_get_type (thread -> pending_object ) == RT_Object_Class_Mutex ))
240
+ {
241
+ /* for ready thread, change queue; otherwise simply update the priority */
242
+ if ((RT_SCHED_CTX (thread ).stat & RT_THREAD_STAT_MASK ) == RT_THREAD_READY )
243
+ {
244
+ /* remove thread from schedule queue first */
245
+ rt_sched_remove_thread (thread );
246
+
247
+ /* change thread priority */
248
+ RT_SCHED_PRIV (thread ).current_priority = priority ;
249
+
250
+ /* recalculate priority attribute */
251
+ #if RT_THREAD_PRIORITY_MAX > 32
252
+ RT_SCHED_PRIV (thread ).number = RT_SCHED_PRIV (thread ).current_priority >> 3 ; /* 5bit */
253
+ RT_SCHED_PRIV (thread ).number_mask = 1 << RT_SCHED_PRIV (thread ).number ;
254
+ RT_SCHED_PRIV (thread ).high_mask = 1 << (RT_SCHED_PRIV (thread ).current_priority & 0x07 ); /* 3bit */
255
+ #else
256
+ RT_SCHED_PRIV (thread ).number_mask = 1 << RT_SCHED_PRIV (thread ).current_priority ;
257
+ #endif /* RT_THREAD_PRIORITY_MAX > 32 */
258
+ RT_SCHED_CTX (thread ).stat = RT_THREAD_INIT ;
259
+
260
+ /* insert thread to schedule queue again */
261
+ rt_sched_insert_thread (thread );
262
+ }
263
+ else
264
+ {
265
+ RT_SCHED_PRIV (thread ).current_priority = priority ;
266
+
267
+ /* recalculate priority attribute */
268
+ #if RT_THREAD_PRIORITY_MAX > 32
269
+ RT_SCHED_PRIV (thread ).number = RT_SCHED_PRIV (thread ).current_priority >> 3 ; /* 5bit */
270
+ RT_SCHED_PRIV (thread ).number_mask = 1 << RT_SCHED_PRIV (thread ).number ;
271
+ RT_SCHED_PRIV (thread ).high_mask = 1 << (RT_SCHED_PRIV (thread ).current_priority & 0x07 ); /* 3bit */
272
+ #else
273
+ RT_SCHED_PRIV (thread ).number_mask = 1 << RT_SCHED_PRIV (thread ).current_priority ;
274
+ #endif /* RT_THREAD_PRIORITY_MAX > 32 */
275
+ }
276
+ }
277
+
278
+ return RT_EOK ;
279
+ }
280
+
227
281
#ifdef RT_USING_OVERFLOW_CHECK
228
282
void rt_scheduler_stack_check (struct rt_thread * thread )
229
283
{
0 commit comments