开发者

context switch in Linux

开发者 https://www.devze.com 2023-02-22 14:08 出处:网络
hello everyone I found this function in Kernel of the Linux: inline task_t *context_sw开发者_运维知识库itch(task_t *prev, task_t *next) {

hello everyone I found this function in Kernel of the Linux:

inline task_t *context_sw开发者_运维知识库itch(task_t *prev, task_t *next) {
...

switch_to(prev, next, prev);
return prev;
}

this function is making context switch, my question is why this function should be inline and not macro for example, thanks in advance...


It may not be a macro because a macro to do this would evaluate prev and next twice each, when they may be expressions with side effects. Also, after some searching I found that switch_to is (on some platforms) a macro that is a statement in braces, and therefore cannot return a value to be used in an expression.

I found some of this info here: https://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:task_switching


Macros are a way to make inline functions, when your C compiler does not do inline functions. A macro, contrary to inline functions, won't do compile-time parameters verification. So inline function are better for maintenance.

0

精彩评论

暂无评论...
验证码 换一张
取 消