最近学习锁已有点走火入魔,然后做了以下这个测试(虽然不知道有什么用,但是做个记录=-=):
测试内容:在spin_lock获取了锁,且不unlock的情况下对数据进行访问。
相关代码
1、read函数:
ssize_t spin_lock_sleep_read(struct file * filp, char __user * buf, size_t count,
loff_t * f_pos)
{
struct spin_lock_sleep_dev *dev = filp->private_data;
ssize_t retval = 0;
spin_lock(&dev->lock);
dev->str = "wrtie in spin lock!";
//spin_unlock(&dev->lock); 这部分会在退出module的时候做
return retval;
}
2、write函数:
ssize_t spin_lock_sleep_write(struct file * filp, const char __user * buf,
size_t count, loff_t * f_pos)
{
struct spin_lock_sleep_dev *dev = filp->private_data;
ssize_t retval = 0;
dev->str = "write something to test!";
return retval;
}
3、退出module函数:
void spin_lock_sleep_cleanup(void)
{
int i;
dev_t devno = MKDEV(spin_lock_sleep_major, spin_lock_sleep_minor);
printk(KERN_INFO "spin_lock sleep module unloaded now!\n");
if (spin_lock_sleep_devices) {
for (i = 0; i < spin_lock_sleep_nr_devs; i++) {
printk("%s\n",spin_lock_sleep_devices[i].str);
if(spin_is_locked(&(spin_lock_sleep_devices[i].lock)) != 0)
{
printk("unlock now!\n");
spin_unlock(&spin_lock_sleep_devices[i].lock);
}
cdev_del(&spin_lock_sleep_devices[i].cdev);
}
kfree(spin_lock_sleep_devices);
}
unregister_chrdev_region(devno, spin_lock_sleep_nr_devs);
}
1、常规操作:insmod module、创建设备节点
2、读设备节点(执行read函数),如下图,自旋锁锁上不解锁
3、写设备节点(执行write函数),如下图
4、注销module,查看相关数据,已被修改=-=
阅读(338) | 评论(0) | 转发(0) |