C++ OSA Thread Code Design?

cancel
Showing results for 
Search instead for 
Did you mean: 

C++ OSA Thread Code Design?

350 Views
tharonhall
Contributor IV

So the PEx generated code is for C, and not specifically for C++. I have found that when compiling C++ and including the PEx header files, you may get into some challenging compile issues where C++ doesn't allow something that is valid in C. However, even with these challenges, I have workarounds in place that are allowing me to code in C++.

I am running the FreeRTOS flavor of OSA, but again, my code is in C++. not C. Because calling C++ from C can be tricky at best, I simply created a C function in the C++ .cpp file and pass a pointer to it when I create my threads. The C function then manipulates data in the class. However, as you can imagine, the C function is not actually part of the class itself, and everything has to be public for it to access it (or getter/setters) and everything defined within the class, such as enums, has be to prefaced with the Class name to access it.

Due to the schedule pressure I am under, I really can't take the time to experiment with the best way to implement this, so I have stuck with the C function approach. However, this is actually pretty painful. Therefore, I was wondering if there is a proven pattern folks are using to tackle this particular issue? Calling a member function in the class from the C routine might be one approach, and I do pass the this pointer of the parent class to the thread so it can access its instance's data.

Thanks! Happy Coding :smileyhappy:

Tags (5)
0 Kudos
0 Replies