down_interruptible()
来源:互联网 发布:信捷plc编程教学视频 编辑:程序博客网 时间:2024/06/07 06:05
最近研究了一下linux驱动,发现有很多同学对down_interruptible() 函数不是很理解。
现在就2.6.38.8 内核
down_interruptible()是处理信号量的函数。他的返回值有三种 1. “0” 2. “-ETIME”3.“-EINTR”
0 代表正常返回
-ETIME 等待超时
-EINTR 中断
函数的运作方式:
如果sem->count >0 (信号量允许访问) 注,关于信号量的详细原理参见操作系统进程同步相关的内容
返回0 (正常返回)
否则进行等待。
内核源码为
int down_interruptible(struct semaphore*sem)
{
unsigned long flags;
intresult = 0;
spin_lock_irqsave(&sem->lock, flags);//信号量自旋锁
if(likely(sem->count > 0))
sem->count--;
else
result = __down_interruptible(sem);//进入等待
spin_unlock_irqrestore(&sem->lock, flags);
return result;
}
__down_interruptible()
调用__down_common()
__down_common()中有for循环
当有中断信号时返回 -EINTR ,当等待超时时返回 -ETIME.
信号量变为可访问状态时返回0
顺便提一下,信号的信号量是不同的,需要区分。
- down_interruptible()
- 深入浅出down_interruptible
- down_interruptible函数
- down_interruptible如何理解
- 设备驱动-----down_interruptible函数
- 深入浅出down_interruptible函数
- down_interruptible函数和down函数的问题
- linux 中信号量 down_interruptible 和 down操作
- Linux 设备驱动--- 并发 之- 信号量 --- semaphore --- down_interruptible --- 按键信号量使用
- Struts2整合JSON
- 谷歌最新创意人体LOGO
- OSCache介绍
- 在Oracle库中查找所有表的相关信息
- ORA-27101: shared memory realm does not exist 错误的处理
- down_interruptible()
- log4j中配置日志文件相对路径
- 一道面试题
- java环境配置
- 前端开发 如何提高工作效率
- linux周六
- KScope安装
- virtual destructor的使用
- Linux hrtimer的实现