学习内核第一天
时间:2006-07-06 来源:anhongkui
学习内核第一天,大致看了看linux内核里的双链表结构,并写了个简单的程序
#define __KERNEL__
#include <linux/list.h>
struct mylist {
struct list_head list;
int index;
}; struct mylist top_conn; void
add_top_conn(struct mylist *list)
{
list_add(&list->list, &top_conn.list);
} void
print_top_conn(void)
{
struct list_head *ptr;
struct mylist *conn; for (ptr = top_conn.list.next; \
ptr != &top_conn.list; ptr = ptr->next)
{
conn = list_entry(ptr, struct mylist, list);
printf("index: %d \n", conn->index);
}
} int
main(void)
{
struct mylist a;
struct mylist b;
struct mylist c;
a.index=1;
b.index=2;
c.index=4; INIT_LIST_HEAD(&top_conn.list);
add_top_conn(&a);
add_top_conn(&b);
add_top_conn(&c);
print_top_conn(); return 1;
}
struct list_head list;
int index;
}; struct mylist top_conn; void
add_top_conn(struct mylist *list)
{
list_add(&list->list, &top_conn.list);
} void
print_top_conn(void)
{
struct list_head *ptr;
struct mylist *conn; for (ptr = top_conn.list.next; \
ptr != &top_conn.list; ptr = ptr->next)
{
conn = list_entry(ptr, struct mylist, list);
printf("index: %d \n", conn->index);
}
} int
main(void)
{
struct mylist a;
struct mylist b;
struct mylist c;
a.index=1;
b.index=2;
c.index=4; INIT_LIST_HEAD(&top_conn.list);
add_top_conn(&a);
add_top_conn(&b);
add_top_conn(&c);
print_top_conn(); return 1;
}
相关阅读 更多 +