include/linux/mutex.h
Source file repositories/reference/linux-study-clean/include/linux/mutex.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/mutex.h- Extension
.h- Size
- 8924 bytes
- Lines
- 273
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/current.hlinux/list.hlinux/spinlock_types.hlinux/lockdep.hlinux/atomic.hasm/processor.hlinux/osq_lock.hlinux/debug_locks.hlinux/cleanup.hlinux/mutex_types.h
Detected Declarations
struct devicefunction mutex_destroyfunction __mutex_initfunction __mutex_initfunction __mutex_initfunction __mutex_initfunction __devm_mutex_init
Annotated Snippet
static inline void mutex_destroy(struct mutex *lock) {}
#endif
/**
* mutex_init - initialize the mutex
* @mutex: the mutex to be initialized
*
* Initialize the mutex to unlocked state.
*
* It is not allowed to initialize an already locked mutex.
*/
#define mutex_init(mutex) \
do { \
static struct lock_class_key __key; \
\
__mutex_init((mutex), #mutex, &__key); \
} while (0)
/**
* mutex_init_with_key - initialize a mutex with a given lockdep key
* @mutex: the mutex to be initialized
* @key: the lockdep key to be associated with the mutex
*
* Initialize the mutex to the unlocked state.
*
* It is not allowed to initialize an already locked mutex.
*/
#define mutex_init_with_key(mutex, key) __mutex_init((mutex), #mutex, (key))
#ifndef CONFIG_PREEMPT_RT
#define __MUTEX_INITIALIZER(lockname) \
{ .owner = ATOMIC_LONG_INIT(0) \
, .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
, .first_waiter = NULL \
__DEBUG_MUTEX_INITIALIZER(lockname) \
__DEP_MAP_MUTEX_INITIALIZER(lockname) }
#define DEFINE_MUTEX(mutexname) \
struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
#ifdef CONFIG_DEBUG_LOCK_ALLOC
void mutex_init_lockdep(struct mutex *lock, const char *name, struct lock_class_key *key);
static inline void __mutex_init(struct mutex *lock, const char *name,
struct lock_class_key *key)
{
mutex_init_lockdep(lock, name, key);
}
#else
extern void mutex_init_generic(struct mutex *lock);
static inline void __mutex_init(struct mutex *lock, const char *name,
struct lock_class_key *key)
{
mutex_init_generic(lock);
}
#endif /* !CONFIG_DEBUG_LOCK_ALLOC */
/**
* mutex_is_locked - is the mutex locked
* @lock: the mutex to be queried
*
* Returns true if the mutex is locked, false if unlocked.
*/
extern bool mutex_is_locked(struct mutex *lock);
#else /* !CONFIG_PREEMPT_RT */
/*
* Preempt-RT variant based on rtmutexes.
*/
#define __MUTEX_INITIALIZER(mutexname) \
{ \
.rtmutex = __RT_MUTEX_BASE_INITIALIZER(mutexname.rtmutex) \
__DEP_MAP_MUTEX_INITIALIZER(mutexname) \
}
#define DEFINE_MUTEX(mutexname) \
struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
#define mutex_is_locked(l) rt_mutex_base_is_locked(&(l)->rtmutex)
#ifdef CONFIG_DEBUG_LOCK_ALLOC
extern void mutex_rt_init_lockdep(struct mutex *mutex, const char *name,
struct lock_class_key *key);
static inline void __mutex_init(struct mutex *lock, const char *name,
struct lock_class_key *key)
{
Annotation
- Immediate include surface: `asm/current.h`, `linux/list.h`, `linux/spinlock_types.h`, `linux/lockdep.h`, `linux/atomic.h`, `asm/processor.h`, `linux/osq_lock.h`, `linux/debug_locks.h`.
- Detected declarations: `struct device`, `function mutex_destroy`, `function __mutex_init`, `function __mutex_init`, `function __mutex_init`, `function __mutex_init`, `function __devm_mutex_init`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.