最近在做linux内核编程,最深的一点感触是:算法的巧妙,犹如看一场高明杂技
真正的程序员那是键盘上灵动的舞者。
写面写的是一个调用内核的hlist测试代码。
/*
*
*how to program use the hlist in kernel
*
*/
#include<linux/module.h>
#include<linux/init.h> /* kind of macros */
#include<linux/kernel.h>
#include<linux/types.h>
#include<linux/list.h>
#include<linux/slab.h>
unsigned int len_hash = 100;
struct hlist_head* hash[100];
void get_random_bytes(void *buf,int nbytes);
/* define the data strc */
typedef struct _data_node{
unsigned int data;
struct hlist_node node;
} data_node_strc;
/* init the hash-chain */
void init_hash(void)
{
unsigned int i=0;
for(i=0;i<len_hash;i++)
{
hash[i] = (struct hlist_head*)kmalloc(sizeof(struct hlis