Chinaunix首页 | 论坛 | 博客
  • 博客访问: 685009
  • 博文数量: 152
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1793
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-12 12:26
个人简介

相信自己,只有不想做的,没有做不到的。

文章分类

全部博文(152)

文章存档

2021年(1)

2015年(2)

2014年(74)

2013年(75)

分类: LINUX

2013-09-24 20:59:47

linux底层驱动的机制之原子操作

//原子操作
1,定义并初始化
atomic_t V = ATOMIC_INIT(1);
静态定义,带初始化
2操作
static int hello_open (struct inode *inode, struct file *file)
{
 if(atomic_dec_and_test(&V))//先V --,判断V == 0 ;
 {
  return 0;
 }
 else
 {
  atomic_inc(&V); //判断V == 0 在 V++;
  return -EBUSY;
 }
}
static int hello_release (struct inode *inode, struct file *file)
{
 atomic_inc(&V);//成功打开关闭,把减去的值加回去
 printk("call hello release\n");
 return 0;
}

 

阅读(891) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~