添加DEFINE_WAIT无法在 linux 模块中编译



我通过调用DEFINE_WAIT添加了一个等待队列条目,但代码无法编译。

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
MODULE_LICENSE("GPL");
DEFINE_WAIT(mywait);
static int __init test_hello_init(void)
{
return 0;
}
static void __exit test_hello_exit(void)
{
}
module_init(test_hello_init);
module_exit(test_hello_exit);

它失败并出现以下错误,指出初始值设定项元素不是常量。

In file included from ./include/linux/thread_info.h:21:0,
from ./arch/x86/include/asm/preempt.h:7,
from ./include/linux/preempt.h:78,
from ./include/linux/spinlock.h:51,
from ./include/linux/seqlock.h:36,
from ./include/linux/time.h:6,
from ./include/linux/stat.h:19,
from ./include/linux/module.h:10,
from /home/linuxtrainer/Linux_Device_Drivers/day20/3_waitqueue/2/hello.c:2:
./arch/x86/include/asm/current.h:18:17: error: initializer element is not constant
#define current get_current()

在test_hello_init作品中添加DEFINE_WAIT,有什么区别?

DEFINE_WAIT()使用不是编译时常量的初始化器 - 它需要在进程上下文中执行 - 因此不能在文件范围内使用。

它应该直接在将要执行等待的函数中使用。