Skip to content

Commit

Permalink
update change prio func
Browse files Browse the repository at this point in the history
  • Loading branch information
zmshahaha committed Aug 29, 2024
1 parent 9a84c13 commit b1b5462
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/rtsched.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ rt_err_t rt_sched_thread_close(struct rt_thread *thread);
rt_err_t rt_sched_thread_ready(struct rt_thread *thread);
rt_err_t rt_sched_thread_suspend(struct rt_thread *thread, rt_sched_lock_level_t level);
rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t priority);
rt_err_t rt_sched_thread_change_curr_priority(struct rt_thread *thread, rt_uint8_t priority);
rt_err_t rt_sched_thread_bind_cpu(struct rt_thread *thread, int cpu);
rt_uint8_t rt_sched_thread_is_suspended(struct rt_thread *thread);
rt_err_t rt_sched_thread_timer_stop(struct rt_thread *thread);
Expand Down
6 changes: 3 additions & 3 deletions src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ rt_inline void _thread_update_priority(struct rt_thread *thread, rt_uint8_t prio
LOG_D("thread:%s priority -> %d", thread->parent.name, priority);

/* change priority of the thread */
ret = rt_sched_thread_change_priority(thread, priority);
ret = rt_sched_thread_change_curr_priority(thread, priority);

while ((ret == RT_EOK) && rt_sched_thread_is_suspended(thread))
{
Expand Down Expand Up @@ -904,7 +904,7 @@ rt_inline void _thread_update_priority(struct rt_thread *thread, rt_uint8_t prio
{
thread = pending_mutex->owner;

ret = rt_sched_thread_change_priority(thread, mutex_priority);
ret = rt_sched_thread_change_curr_priority(thread, mutex_priority);
}
else
{
Expand All @@ -931,7 +931,7 @@ static rt_bool_t _check_and_update_prio(rt_thread_t thread, rt_mutex_t mutex)
/* get the highest priority in the taken list of thread */
priority = _thread_get_mutex_priority(thread);

rt_sched_thread_change_priority(thread, priority);
rt_sched_thread_change_curr_priority(thread, priority);

/**
* notify a pending reschedule. Since scheduler is locked, we will not
Expand Down
22 changes: 21 additions & 1 deletion src/scheduler_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ rt_err_t rt_sched_tick_increase(rt_tick_t tick)
/**
* @brief Update priority of the target thread
*/
rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t priority)
rt_err_t rt_sched_thread_change_curr_priority(struct rt_thread *thread, rt_uint8_t priority)
{
RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX);
RT_SCHED_DEBUG_IS_LOCKED;
Expand Down Expand Up @@ -224,6 +224,26 @@ rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t pr
return RT_EOK;
}

/**
* @brief Update priority of the target thread
*/
rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t priority)
{
RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX);
RT_SCHED_DEBUG_IS_LOCKED;

/* change thread init priority */
RT_SCHED_PRIV(thread).init_priority = priority;

/* if this thread takes mutex, its current prio is controlled by mutex PI protocol */
if (rt_list_isempty(&thread->taken_object_list) && !(thread->pending_object && (rt_object_get_type(thread->pending_object) == RT_Object_Class_Mutex)))
{
rt_sched_thread_change_curr_priority(thread, priority);
}

return RT_EOK;
}

#ifdef RT_USING_OVERFLOW_CHECK
void rt_scheduler_stack_check(struct rt_thread *thread)
{
Expand Down

0 comments on commit b1b5462

Please sign in to comment.