-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Update function rt_thread_suspend in src/thread.c. #8856
base: master
Are you sure you want to change the base?
Conversation
看下上一个函数的说明: /**
* @brief This function will suspend the specified thread and change it to suspend state.
*
* @note This function ONLY can suspend current thread itself.
* rt_thread_suspend(rt_thread_self());
*
* Do not use the rt_thread_suspend to suspend other threads. You have no way of knowing what code a
* thread is executing when you suspend it. If you suspend a thread while sharing a resouce with
* other threads and occupying this resouce, starvation can occur very easily.
*
* @param thread the thread to be suspended.
* @param suspend_flag status flag of the thread to be suspended.
*
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
* If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_suspend_with_flag(rt_thread_t thread, int suspend_flag)
{
return rt_thread_suspend_to_list(thread, RT_NULL, 0, suspend_flag);
} |
感谢熊老大的指点,我刚开始学习RTT和阅读源码,会有许多不足望多多指点。 确实原有的方案已经解决了挂起自身的问题,但使用 |
但是之前的方式都是自行在外面调用,所以如果突然改成内部调用,那么就会出现相关所有代码都需要仔细查看一遍,同时做好相关的测试工作。 |
这确实比较麻烦,我现在有两个想法:
以上方法各有优缺点,不知道您怎么看?是否有更好的方法? |
Make it easier and safer for users to suspend the current thread.
Make it easier and safer for users to suspend the current thread.
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
用户在不是很了解的情况下挂起自身线程,可能不会调用
rt_schedule
。更新 src/thread.c 中的
rt_thread_suspend
函数,使挂起当前线程更方便、更安全。你的解决方案是什么 (what is your solution)
在一般的使用中挂起自己常用
rt_thread_suspend
函数,该函数内部对于RT_NULL
并未使用而时作为错误进行断言。因此借鉴FreeRTOS,在传入到内部实现之前,先判断参数是否为
RT_NULL
,并替换为当前线程,并在之后调用rt_schedule
。同时添加
rt_thread_suspend
函数自身注释,以便使用。请提供验证的bsp和config (provide the config and bsp)
BSP:
.config:
action:
]
当前拉取/合并请求的状态 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