[C++] 纯文本查看 复制代码
/**
* list_for_each_entry - iterate over list of given type
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry(pos, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member); \
prefetch(pos->member.next), &pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member))
[C++] 纯文本查看 复制代码
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/version.h>
#include <linux/list.h>
MODULE_LICENSE("Dual BSD/GPL");
struct module *m = &__this_module;
static void list_module_test(void)
{
struct module *mod;
list_for_each_entry(mod, m->list.prev, list)
printk ("%s\n", mod->name);
}
static int list_module_init (void)
{
list_module_test();
return 0;
}
static void list_module_exit (void)
{
printk ("unload listmodule.ko\n");
}
module_init(list_module_init);
module_exit(list_module_exit);