c - DEFINE_PER_CPU 定义指向结构的指针数组

标签 c linux

使用 DEFINE_PER_CPU 时,以下定义有效在Linux内核中:

DEFINE_PER_CPU(int, x);
DEFINE_PER_CPU(char[10], c);
DEFINE_PER_CPU(struct foo, f);

我现在想使用相同的方法定义一个指向结构的指针数组。

假设该结构名为struct foo,并将命名为bar。然后我尝试了:

DEFINE_PER_CPU(struct *foo[100], bar);

但是,它会导致编译错误。我还尝试了其他几种排列,但无法使其发挥作用。谁能指出什么可行,为什么?

我知道解决方法可能是创建一个包装器结构来存储可由上述方法之一使用的指针,但我想知道如何使其与指针一起使用。

编辑:struct foo 也不起作用。

最佳答案

以下作品:

DEFINE_PER_CPU(__typeof__(struct foo *)[100], bar);

引用文献:

[1] Linux kernel header包含 DEFINE_PER_CPU 的定义。

[2] GCC documentation typeof

关于c - DEFINE_PER_CPU 定义指向结构的指针数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37728845/

相关文章:

c - Eventloop 具有高 ksoftirqd 负载; nginx 不会,但会执行相同的系统调用。为什么?

c - malloc 和 free 的错综复杂

linux - 系统API和系统调用API的区别

linux - 无密码 SSH 仅适用于 Debug模式

linux - Flutter for Linux 构建失败

c - 信号量的3个线程和消费者生产者问题

Android ndk 和动态加载库与 dlopen

c - 为什么 `while ((ch = getchar()) != EOF)` 是常见的习惯用法?

mysql - InnoDB : Operating system error number 13 in a file operation not fixed after changing permissions in/var/lib/mysql/or disabling selinux

linux - Bash 脚本 - 管道命令回显