Conversation
src/thread.c
Outdated
| rt_sched_lock_level_t slvl; | ||
| rt_sched_lock(&slvl); | ||
| error = rt_sched_thread_change_priority(thread, *(rt_uint8_t *)arg); | ||
| error = rt_sched_thread_set_priority(thread, *(rt_uint8_t *)arg); |
There was a problem hiding this comment.
这个API为什么不直接在 rt_sched_thread_change_priority 基础上修改呢?
There was a problem hiding this comment.
这个API为什么不直接在
rt_sched_thread_change_priority基础上修改呢?
原API还有其它地方在调用,如_thread_update_priority、_check_and_update_prio,这些地方不能调整init_priority。我理解init_priority用于设置task的正常优先级,而current_priority可能会因为使用mutex改变,是临时优先级,当使用完mutex后task会返回到init_priority。
There was a problem hiding this comment.
这个API为什么不直接在
rt_sched_thread_change_priority基础上修改呢?
原API还有其它地方在调用,如_thread_update_priority、_check_and_update_prio,这些地方不能调整init_priority。我理解init_priority用于设置task的正常优先级,而current_priority可能会因为使用mutex改变,是临时优先级,当使用完mutex后task会返回到init_priority。
建议在rt_thread_control中新增一个:RT_THREAD_CTRL_SET_PRIORITY的选项
There was a problem hiding this comment.
建议在
rt_thread_control中新增一个:RT_THREAD_CTRL_SET_PRIORITY的选项
新增涉及到更改rtdef.h,请为RT_THREAD_CTRL_SET_PRIORITY提供一个合适值,0x05?
#define RT_THREAD_CTRL_STARTUP 0x00 /**< Startup thread. */
#define RT_THREAD_CTRL_CLOSE 0x01 /**< Close thread. */
#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. */
There was a problem hiding this comment.
建议在
rt_thread_control中新增一个:RT_THREAD_CTRL_SET_PRIORITY的选项新增涉及到更改
rtdef.h,请为RT_THREAD_CTRL_SET_PRIORITY提供一个合适值,0x05?#define RT_THREAD_CTRL_STARTUP 0x00 /**< Startup thread. */ #define RT_THREAD_CTRL_CLOSE 0x01 /**< Close thread. */ #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. */
可以
|
change prio 和 set prio这两个函数有什么区别呀,这个名字没有注释的话很不好区分 |
关于函数名字和注释,你们可以协商定一个告诉我或者直接修改。 |
|
@wycwyhwyq 看了下, static void _rt_sched_update_priority(struct rt_thread *thread, rt_uint8_t priority, rt_bool_t update_init_prio)
{
if (update_init_prio)
{
RT_SCHED_PRIV(thread).init_priority = priority;
}
/* change thread priority */
RT_SCHED_PRIV(thread).current_priority = priority;
/* recalculate priority attribute */
#if RT_THREAD_PRIORITY_MAX > 32
RT_SCHED_PRIV(thread).number = RT_SCHED_PRIV(thread).current_priority >> 3; /* 5bit */
RT_SCHED_PRIV(thread).number_mask = 1 << RT_SCHED_PRIV(thread).number;
RT_SCHED_PRIV(thread).high_mask = 1 << (RT_SCHED_PRIV(thread).current_priority & 0x07); /* 3bit */
#else
RT_SCHED_PRIV(thread).number_mask = 1 << RT_SCHED_PRIV(thread).current_priority;
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
}
/**
* @brief Reset priority of the target thread
*/
rt_err_t rt_sched_thread_reset_priority(struct rt_thread *thread, rt_uint8_t priority)
{
RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX);
RT_SCHED_DEBUG_IS_LOCKED;
/* for ready thread, change queue; otherwise simply update the priority */
if ((RT_SCHED_CTX(thread).stat & RT_THREAD_STAT_MASK) == RT_THREAD_READY)
{
/* remove thread from schedule queue first */
rt_sched_remove_thread(thread);
_rt_sched_update_priority(thread, priority, RT_TRUE);
RT_SCHED_CTX(thread).stat = RT_THREAD_INIT;
/* insert thread to schedule queue again */
rt_sched_insert_thread(thread);
}
else
{
_rt_sched_update_priority(thread, priority, RT_TRUE);
}
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;
/* for ready thread, change queue; otherwise simply update the priority */
if ((RT_SCHED_CTX(thread).stat & RT_THREAD_STAT_MASK) == RT_THREAD_READY)
{
/* remove thread from schedule queue first */
rt_sched_remove_thread(thread);
_rt_sched_update_priority(thread, priority, RT_FALSE);
RT_SCHED_CTX(thread).stat = RT_THREAD_INIT;
/* insert thread to schedule queue again */
rt_sched_insert_thread(thread);
}
else
{
_rt_sched_update_priority(thread, priority, RT_FALSE);
}
return RT_EOK;
} |
API命名上建议:rt_sched_thread_set_priority → rt_sched_thread_reset_priority,体现 "重置" 的含义,即既修改 init_priority 又修改 current_priority,表示线程的初始优先级和当前优先级都被更新。 注释这么写会好些 |
|
你好,我最近太忙了。我看了一下,rt_sched_thread_set_priority 和 rt_sched_thread_change_priority 很多逻辑是重复的,可否通过bool类型来区分一下逻辑。 |
There is a PR submitted but has not been merged: RT-Thread#10050. The PR is a bit different against this patch.
There is a PR submitted but has not been merged: RT-Thread#10050. The PR is a bit different against this patch.
There is a PR submitted but has not been merged: RT-Thread#10050. The PR is a bit different against this patch.
There is a PR submitted but has not been merged: RT-Thread#10050. The PR is a bit different against this patch.
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
#10049
你的解决方案是什么 (what is your solution)
请提供验证的bsp和config (provide the config and bsp)
risc-v/K230
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up