| ||||||||
Technical Support On-Line Manuals C251 User's Guide | Reentrant FunctionsA reentrant function may be shared by several processes at the same time. When a reentrant function is executing, another process can interrupt the execution and then begin to execute that same reentrant function. By default, the C251 compiler generates static code, which means that functions cannot normally be called recursively or in a fashion which causes reentrancy. The advantage of static code is that function arguments and local variables are stored in fixed memory locations which allows the 251 MCU fast variable access. The reentrant function attribute allows you to declare functions that may be reentrant and, therefore, may be called recursively. For example:
int calc (char i, int b) reentrant {
int x;
x = table [i];
return (x * b);
}
#pragma FUNCTIONS (reentrant) /* C251 generates reentrant CODE */
int func (unsigned char index) {
return (table[index);
}
#pragma FUNCTIONS (static) /* select static CODE again */
Reentrant functions may be called recursively and may be called simultaneously by two or more processes. Reentrant functions are often required in real-time applications or in situations where interrupt code and non-interrupt code must share a function. As in the above example, you may selectively define (using the reentrant attribute or the FUNCTIONS directive) functions as reentrant. Reentrant code uses the 251 hardware stack area for non register parameters and automatic variables. Refer to Hardware Stack for a detailed explanation about the stack layout in reentrant code. For reentrant functions a few restrictions exist due to the 251 hardware architecture:
Note
| |||||||
| ||||||||