Mutinifni Mutinifni - 4 months ago 10
Linux Question

DEFINE_PER_CPU to define an array of pointers to structures

The following definitions work when using DEFINE_PER_CPU in the Linux kernel:

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

I now want to define an array of pointers to structures using the same.

Assume the structure is called
struct foo
, and is to be named
. I then tried:

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

However, it results in a compilation error. I also tried a couple of other permutations, but am unable to make it work. Can anyone please point out what will work, and why?

I understand that a workaround could be to create a wrapper structure that stores the pointer which can be used by one of the methods above, but I would like to know how to make it work with pointers.

EDIT: Struct foo does not work either.


The following works:

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


[1] Linux kernel header containing the definition of DEFINE_PER_CPU.

[2] GCC documentation of typeof.