博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux Kernel互斥量获取和释放
阅读量:4154 次
发布时间:2019-05-25

本文共 2633 字,大约阅读时间需要 8 分钟。

mutex_lock
mutex_lock_interruptible
mutex_lock_killable
mutex_trylock
mutex_unlock
atomic_dec_and_mutex_lock
 
 
/** * mutex_lock - acquire the mutex * @lock: the mutex to be acquired * * Lock the mutex exclusively for this task. If the mutex is not * available right now, it will sleep until it can get it. * * The mutex must later on be released by the same task that * acquired it. Recursive locking is not allowed. The task * may not exit without first unlocking the mutex. Also, kernel * memory where the mutex resides must not be freed with * the mutex still locked. The mutex must first be initialized * (or statically defined) before it can be locked. memset()-ing * the mutex to 0 is not allowed. * * ( The CONFIG_DEBUG_MUTEXES .config option turns on debugging *   checks that will enforce the restrictions and will also do *   deadlock debugging. ) * * This function is similar to (but not equivalent to) down(). */void __sched mutex_lock(struct mutex *lock){	might_sleep();	/*	 * The locking fastpath is the 1->0 transition from	 * 'unlocked' into 'locked' state.	 */	__mutex_fastpath_lock(&lock->count, __mutex_lock_slowpath);	mutex_set_owner(lock);}
 
/** * mutex_trylock - try to acquire the mutex, without waiting * @lock: the mutex to be acquired * * Try to acquire the mutex atomically. Returns 1 if the mutex * has been acquired successfully, and 0 on contention. * * NOTE: this function follows the spin_trylock() convention, so * it is negated from the down_trylock() return values! Be careful * about this when converting semaphore users to mutexes. * * This function must not be used in interrupt context. The * mutex must be released by the same task that acquired it. */int __sched mutex_trylock(struct mutex *lock){	int ret;	ret = __mutex_fastpath_trylock(&lock->count, __mutex_trylock_slowpath);	if (ret)		mutex_set_owner(lock);	return ret;}
 
/** * mutex_unlock - release the mutex * @lock: the mutex to be released * * Unlock a mutex that has been locked by this task previously. * * This function must not be used in interrupt context. Unlocking * of a not locked mutex is not allowed. * * This function is similar to (but not equivalent to) up(). */void __sched mutex_unlock(struct mutex *lock){	/*	 * The unlocking fastpath is the 0->1 transition from 'locked'	 * into 'unlocked' state:	 */#ifndef CONFIG_DEBUG_MUTEXES	/*	 * When debugging is enabled we must not clear the owner before time,	 * the slow path will always be taken, and that clears the owner field	 * after verifying that it was indeed current.	 */	mutex_clear_owner(lock);#endif	__mutex_fastpath_unlock(&lock->count, __mutex_unlock_slowpath);}

转载地址:http://zwhti.baihongyu.com/

你可能感兴趣的文章
九度:题目1034:寻找大富翁
查看>>
第六章 背包问题——01背包
查看>>
51nod 分类
查看>>
1136 . 欧拉函数
查看>>
面试题:强制类型转换
查看>>
Decorator模式
查看>>
Template模式
查看>>
Observer模式
查看>>
高性能服务器设计
查看>>
性能扩展问题要趁早
查看>>
MySQL-数据库、数据表结构操作(SQL)
查看>>
OpenLDAP for Windows 安装手册(2.4.26版)
查看>>
图文介绍openLDAP在windows上的安装配置
查看>>
Pentaho BI开源报表系统
查看>>
Pentaho 开发: 在eclipse中构建Pentaho BI Server工程
查看>>
JSP的内置对象及方法
查看>>
android中SharedPreferences的简单例子
查看>>
android中使用TextView来显示某个网址的内容,使用<ScrollView>来生成下拉列表框
查看>>
andorid里关于wifi的分析
查看>>
Spring MVC和Struts2的比较
查看>>