#include <linux/kfifo.h>
#define ELEM 16
static struct kfifo *q;
static spinlock_t q_lock;
int num;
spin_lock_init(&q_lock);
q = kfifo_alloc(sizeof(int)*ELEM, GFP_KERNEL, &q_lock);
if (IS_ERR(q)) {
goto err_all_q;
}
kfifo_put(q, (unsigned char*)&num, sizeof(num));
if(kfifo_get(q, (unsigned char*)&num, sizeof(num)) != sizeof(num)) {
goto err_buf;
}
kfifo_free(q);
本文介绍了一种在Linux内核中使用kfifo进行数据交换的方法。通过定义kfifo结构、初始化自旋锁、分配内存等步骤,实现了整型变量的放入与取出操作,并确保了数据的一致性和完整性。
4185

被折叠的 条评论
为什么被折叠?



