Hello,
May I specify all of functions are reentrant function by directives? I am using RXT51 tiny and my functions are reentrantable. I am tired to declare "reentrant" at the end of every function declaration.
Thank you very much~
What do you mean?
- That all your functions need to be reentraynt. - That all your functions may be reentrant.
A reentrant function can't share it's parameter-passing memory area with other functions, so the memory consumption will increase a lot. That is why only a function that must be reentrant should be specified as reentrant. For smaller functions, it can be better to douplicate the function - one copy for each caller - to avoid this penalty.
In short, if you think that every function in your program needs to be reentrant, then it is time for you to look at your code and figure out what you do wrong.
Hi Sir, Thank you for your reply. What I mean is I got a lot of functions which will be called by different tasks at the same time. As I know, to prevent arguments and locals get corrupted. A function be called by more than one task at the same time should be declared as a reentrant function. (For example:)
int calc (char i, int b) reentrant { int x; x = table [i]; return (x * b); }
I am tired to add the keyword "reentrant" at the end of function declaration because the most of functions are reentrant-able in my application. I wonder if there is a directive such as "#reentrant" can help me to tell compiler that all of the functions are "reentrant" function.
Thanks & Regards.
It is enough that just a couple of functions are not called from multiple threads or recursively for the compiler to be able to find call trees that it can optimize the parameter passing for.
Are you saying that every function in your application is called from multiple threads? That most definitely sounds like you should take a closer look at your design!
Your goal, when developing for '51 processors is to minimize the number of reentrant functions, not find easier way to declare every function reentrant. This is just as productive as asking how you can have the compiler upgrade every integer to 32-bit or maybe 64-bit, or how you can get the compiler to evaluate every single expression as floating point, or how you can get the compiler to treat every single variable as volatile without using the volatile keyword.
Are you really, really sure that you have made a good split of your logic into separate tasks? From your description, it sounds more like all takss are doing basically the same thing, in which case all tasks will make use of the same set of functions.
Hi Sir, I do really understand a reentrant function can slow down the executing performance and I am keeping functions from being that. But the tasks are not simply doing the same thing, but depend on the arguments (structure pointer) doing difference things. Each task does long-winde processes and the code are big engouh to make me decide not to create the same function for each task.
Can we just set compiler not to use fixed memory address to put locals or arguments but use reentrant stack (or similar method) as default?
Sounds like the 8051 is basically the wrong choice for this project?
Is it too late to reconsider?
The full list of available directives is here: http://www.keil.com/support/man/docs/c51/c51_cm_directives.htm
Hi Andy,
Thank you for your notice.
I have checked the URL and the listed directive seems cannot support my requirement.