Linux Kernel 互斥量

    xiaoxiao2021-03-25  52

    /*  * Simple, straightforward mutexes with strict semantics:  *  * - only one task can hold the mutex at a time  * - only the owner can unlock the mutex  * - multiple unlocks are not permitted  * - recursive locking is not permitted  * - a mutex object must be initialized via the API  * - a mutex object must not be initialized via memset or copying  * - task may not exit with mutex held  * - memory areas where held locks reside must not be freed  * - held mutexes must not be reinitialized  * - mutexes may not be used in hardware or software interrupt  *   contexts such as tasklets and timers  *  * These semantics are fully enforced when DEBUG_MUTEXES is  * enabled. Furthermore, besides enforcing the above rules, the mutex  * debugging code also implements a number of additional features  * that make lock debugging easier and faster:  *  * - uses symbolic names of mutexes, whenever they are printed in debug output  * - point-of-acquire tracking, symbolic lookup of function names  * - list of all locks held in the system, printout of them  * - owner tracking  * - detects self-recursing locks and prints out all relevant info  * - detects multi-task circular deadlocks and prints out all affected  *   locks and tasks (and only those tasks)  */ struct mutex { /* 1: unlocked, 0: locked, negative: locked, possible waiters */ atomic_t count; spinlock_t wait_lock; struct list_head wait_list; #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_MUTEX_SPIN_ON_OWNER) struct task_struct *owner; #endif #ifdef CONFIG_MUTEX_SPIN_ON_OWNER struct optimistic_spin_queue osq; /* Spinner MCS lock */ #endif #ifdef CONFIG_DEBUG_MUTEXES void *magic; #endif #ifdef CONFIG_DEBUG_LOCK_ALLOC struct lockdep_map dep_map; #endif };
    转载请注明原文地址: https://ju.6miu.com/read-32841.html

    最新回复(0)