Skip to content

[src] fix mutex bug #10050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions components/lwp/lwp_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ sysret_t sys_setpriority(int which, id_t who, int prio)
for (list = lwp->t_grp.next; list != &lwp->t_grp; list = list->next)
{
thread = rt_list_entry(list, struct rt_thread, sibling);
rt_thread_control(thread, RT_THREAD_CTRL_CHANGE_PRIORITY, &prio);
rt_thread_control(thread, RT_THREAD_CTRL_RESET_PRIORITY, &prio);
}
lwp_pid_lock_release();
return 0;
Expand Down Expand Up @@ -8789,7 +8789,7 @@ sysret_t sys_sched_setparam(pid_t tid, void *param)

if (thread)
{
ret = rt_thread_control(thread, RT_THREAD_CTRL_CHANGE_PRIORITY, (void *)&sched_param->sched_priority);
ret = rt_thread_control(thread, RT_THREAD_CTRL_RESET_PRIORITY, (void *)&sched_param->sched_priority);
}

lwp_tid_dec_ref(thread);
Expand Down Expand Up @@ -8959,7 +8959,7 @@ sysret_t sys_sched_setscheduler(int tid, int policy, void *param)
}

thread = lwp_tid_get_thread_and_inc_ref(tid);
ret = rt_thread_control(thread, RT_THREAD_CTRL_CHANGE_PRIORITY, (void *)&sched_param->sched_priority);
ret = rt_thread_control(thread, RT_THREAD_CTRL_RESET_PRIORITY, (void *)&sched_param->sched_priority);
lwp_tid_dec_ref(thread);

kmem_put(sched_param);
Expand Down
1 change: 1 addition & 0 deletions include/rtdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ enum
#define RT_THREAD_CTRL_CHANGE_PRIORITY 0x02 /**< Change thread priority. */
#define RT_THREAD_CTRL_INFO 0x03 /**< Get thread information. */
#define RT_THREAD_CTRL_BIND_CPU 0x04 /**< Set thread bind cpu. */
#define RT_THREAD_CTRL_RESET_PRIORITY 0x05 /**< Reset thread priority. */

/**
* CPU usage statistics data
Expand Down
1 change: 1 addition & 0 deletions include/rtsched.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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_reset_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
26 changes: 25 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)
static rt_err_t _rt_sched_update_priority(struct rt_thread *thread, rt_uint8_t priority, rt_bool_t update_init_prio)
{
RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX);
RT_SCHED_DEBUG_IS_LOCKED;
Expand All @@ -192,6 +192,10 @@ rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t pr
rt_sched_remove_thread(thread);

/* change thread priority */
if (update_init_prio)
{
RT_SCHED_PRIV(thread).init_priority = priority;
}
RT_SCHED_PRIV(thread).current_priority = priority;

/* recalculate priority attribute */
Expand All @@ -209,6 +213,10 @@ rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t pr
}
else
{
if (update_init_prio)
{
RT_SCHED_PRIV(thread).init_priority = priority;
}
RT_SCHED_PRIV(thread).current_priority = priority;

/* recalculate priority attribute */
Expand All @@ -224,6 +232,22 @@ 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)
{
return _rt_sched_update_priority(thread, priority, RT_FALSE);
}

/**
* @brief Reset priority of the target thread
*/
rt_err_t rt_sched_thread_reset_priority(struct rt_thread *thread, rt_uint8_t priority)
{
return _rt_sched_update_priority(thread, priority, RT_TRUE);
}

#ifdef RT_USING_OVERFLOW_CHECK
void rt_scheduler_stack_check(struct rt_thread *thread)
{
Expand Down
12 changes: 12 additions & 0 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,8 @@ RTM_EXPORT(rt_thread_mdelay);
*
* RT_THREAD_CTRL_BIND_CPU for bind the thread to a CPU.
*
* RT_THREAD_CTRL_RESET_PRIORITY for reset priority level of thread.
*
* @param arg is the argument of control command.
*
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
Expand All @@ -802,6 +804,16 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
return error;
}

case RT_THREAD_CTRL_RESET_PRIORITY:
{
rt_err_t error;
rt_sched_lock_level_t slvl;
rt_sched_lock(&slvl);
error = rt_sched_thread_reset_priority(thread, *(rt_uint8_t *)arg);
rt_sched_unlock(slvl);
return error;
}

case RT_THREAD_CTRL_STARTUP:
{
return rt_thread_startup(thread);
Expand Down