I am using an inhouse developed multi tasking scheduler for 8051. Every function that I write, I need to put reentrant on it. Is it possible to add a compiler directive like the c166 compilers for c51 compiler?
Your problem may not be as bad as it seems. The Keil C Lib has many functions that are pure or reentrant. They are described in the clib documentation. Those functions are reentrant and thread-safe.
The clib non-reentrant fucntions are another pain. Your clear alternative for a better life would be not using the standard clib supplied functions that are not reentrant in your code. You can implement a version of those needed functions in a lib of yours, and the linker will use your version instead of the clib version. This has the advantage of total control, so if you can't write a pure registered function, you can at least use a tempdata static allocation that can be controlled by your task switcher. One very simple way to do this is to have a global pointer that points to the thread local static storage for your clib functions (your tempdata section). Whenever you switch contexts, you can set the pointer to the new thread local storage base address, and the threads will happily live oblivious of one another. This is MUCH faster to switch, and need no locks.
Your own functions are thread safe if they are pure (no explicit global vars and no static vars) and don't have memory temporary storage, i.e., all its vars are stored in banked registers. Again, if you can't write them small to fit banked registers, you can use the above indirect thread local storage pointer solution for your own functions. Since it is private to a single thread, you can use heavy overlaying to keep the footprint small.