Lists handling in Linux kernel

Jan 27, 2016 01:17



struct item {
struct list_head list;
...
// other useful data;
};

struct list_head my_list;
INIT_LIST_HEAD(&my_list);

// FREE LIST
struct item *pe, *pe_temp;
...
list_for_each_entry_safe(pe, pe_temp, &my_list, list)
{
list_del(&pe->list);
// free(pe->data);
kfree(pe);
}

// ADD TO LIST
pe = kzalloc(sizeof(struct item), GFP_KERNEL);
pe->data = add_some_data;

list_add(&pe->list, &my_list);

// TRAVERSE LIST
struct item *p;
list_for_each_entry(p, &my_list, list) {
// process p->data
}

компьютеры, linux

Previous post Next post
Up