Question

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_inited 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_initing 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_deletes, 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.

Was it helpful?

Solution

Never tried it myself, so this is a guess - but did you consider using rt_whoami?

Get the task pointer of the current task.

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top