Linux Kernel互斥量获取和释放

    xiaoxiao2021-03-25  54

    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); }
    转载请注明原文地址: https://ju.6miu.com/read-33120.html

    最新回复(0)