如何检测函数的调用线程是否已经是RTAI实时的?
我正在开发一个在内核和用户空间都使用 RTAI 的大项目。我不会详细介绍该项目,但这里简要介绍一下出现问题的地方。
在用户空间中,我的项目提供了一个供其他人用来编写一些软件的库。这些程序本身可能具有 RTAI 实时线程。
现在,RTAI 中的一些函数要求它们的调用线程已经 rt_thread_inited,因此如果我想在库中的函数中使用它们,我需要通过调用 <代码>rt_thread_init和后来的rt_task_delete
。
现在的问题是:
如果我的函数的调用线程已经是实时的,那么我正在 rt_thread_init
ing,我认为它会失败,但随后我 rt_task_delete
并使其成功线程非实时(除了当线程本身(假设我没有更改任何内容)再次rt_task_delete
s时,RTAI崩溃。
如果我的函数的调用线程不是实时的, 现在一切都很好,
我在函数中采用了一个参数,以便调用函数告诉库它是否是实时的,但是,我想知道 RTAI 是否有一个函数或其他东西。我可以用来自动检测当前线程是否实时。
不知道这里是否有 RTAI 用户(我当然没有看到 RTAI 标签),但希望会有。
I am working on a big project that uses RTAI both in kernel and user spaces. I won't get into the details of the project, but here is briefly where a problem arises.
In user-space, my project provides a library used by other people to write some software. Those programs themselves may have RTAI real-time threads.
Now, some functions in RTAI require that their calling thread have already rt_thread_init
ed so if I want to use them in a function in the library, I need to temporarily make the calling thread real-time by calling rt_thread_init
and later rt_task_delete
.
Now here's the problem:
If the calling thread of my function IS already real-time, then I am rt_thread_init
ing which I assume simply fails, but then I rt_task_delete
and make that thread non-real-time (besides the fact that when the thread itself (assuming I changed nothing) again rt_task_delete
s, RTAI crashes.
If the calling thread of my function IS not real-time, everything is ok.
For now, I resorted to taking a parameter in the function so that the calling function tells the library if it is real-time or not. However, I wanted to know if RTAI has a function or something so I could use to automatically detect whether the current thread is real-time or not.
Don't know if there are any RTAI users here (I certainly didn't see the RTAI tag), but hope there would be.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己从未尝试过,所以这是一个猜测 - 但你考虑过使用 rt_whoami 吗?
https://www.rtai.org/documentation/magma/html /api/api_8c.html#a12
我想如果你处于非 RT 任务中它会失败(返回 NULL?)...
Never tried it myself, so this is a guess - but did you consider using rt_whoami?
https://www.rtai.org/documentation/magma/html/api/api_8c.html#a12
I would imagine it will fail (return NULL?) if you are in a non RT task...