日期:2014-05-16 浏览次数:21032 次
ssize_t my_read(struct file *flip,char __user *buff,size_t cnt,loff_t *off_t) { spin_lock_irqsave(&my_spinlock,flag); /* 变量number是要保护的数据*/ if(copy_to_user(buff,&number,sizeof(int))) { spin_unlock_irqrestore(&my_spinlock,flag); return -EFAULT; } /*延时10秒,为并发创造条件*/ ssleep(10); spin_unlock_irqrestore(&my_spinlock,flag); return 0; } ssize_t my_write(struct file *flip,const char __user *buff,size_t cnt,loff_t *off_t) { spin_lock_irqsave(&my_spinlock,flag); if(copy_from_user(&number,buff,sizeof(int))) { spin_unlock_irqrestore(&my_spinlock,flag); return -EFAULT; } spin_unlock_irqrestore(&my_spinlock,flag); return 0; }