在阅读libev中的文档时,我发现一些语法相当奇怪的C代码。
static void
stdin_cb (EV_P_ ev_io *w, int revents)
{
puts ("stdin ready");
// for one-shot events, one must manually stop the watcher
// with its corresponding stop function.
ev_io_stop (EV_A_ w);
// this causes all nested ev_run's to stop iterating
ev_break (EV_A_ EVBREAK_ALL);
}
我不确定这里的EV_P_
是什么,有人能帮我解释一下吗?
我试过谷歌的语法方法签名在C中,但没有很好的匹配。
2条答案
按热度按时间kgqe7b3p1#
参见版本h:
因此,生产线
扩展到
或
取决于
EV_MULTIPLICITY
的值正如@Shawn所指出的,有一个Macro魔术部分对此进行了解释:
EV_P,EV_P_
bweufnob2#
EV_P_
是一个宏,意思是"一个ev循环作为参数,加上一个逗号"。EV_A_
是一个宏,意思是"一个ev循环作为参数,加上一个逗号"。它们的defined为
或作为
(Some删除了空格,以便更好地匹配。)
这意味着
相当于
或
使用哪组
#define
指令是可配置的。如果
EV_MULTIPLICITY
设置为非零,则使用第一个设置。第一个设置允许在同一个程序中使用多个ev循环(可能在不同的线程中)。如果
EV_MULTIPLICITY
未设置或为零,则使用第二个集合。第二个集合更高效,因为它使用全局变量,而不是向每个ev相关函数传递一个结构。但程序只能有一个事件循环。