include/linux/local_lock_internal.h

Source file repositories/reference/linux-study-clean/include/linux/local_lock_internal.h

File Facts

System
Linux kernel
Corpus path
include/linux/local_lock_internal.h
Extension
.h
Size
8978 bytes
Lines
340
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.

Dependency Surface

Detected Declarations

Annotated Snippet

static inline void local_lock_acquire(local_lock_t *l) { }
static inline void local_trylock_acquire(local_lock_t *l) { }
static inline void local_lock_release(local_lock_t *l) { }
static inline void local_lock_debug_init(local_lock_t *l) { }
#endif /* !CONFIG_DEBUG_LOCK_ALLOC */

#define INIT_LOCAL_LOCK(lockname)	{ LOCAL_LOCK_DEBUG_INIT(lockname) }
#define INIT_LOCAL_TRYLOCK(lockname)	{ LOCAL_TRYLOCK_DEBUG_INIT(lockname) }

#define __local_lock_init(lock)					\
do {								\
	static struct lock_class_key __key;			\
								\
	debug_check_no_locks_freed((void *)lock, sizeof(*lock));\
	lockdep_init_map_type(&(lock)->dep_map, #lock, &__key,  \
			      0, LD_WAIT_CONFIG, LD_WAIT_INV,	\
			      LD_LOCK_PERCPU);			\
	local_lock_debug_init(lock);				\
} while (0)

#define __local_trylock_init(lock)				\
do {								\
	__local_lock_init((local_lock_t *)lock);		\
} while (0)

#define __spinlock_nested_bh_init(lock)				\
do {								\
	static struct lock_class_key __key;			\
								\
	debug_check_no_locks_freed((void *)lock, sizeof(*lock));\
	lockdep_init_map_type(&(lock)->dep_map, #lock, &__key,  \
			      0, LD_WAIT_CONFIG, LD_WAIT_INV,	\
			      LD_LOCK_NORMAL);			\
	local_lock_debug_init(lock);				\
} while (0)

#define __local_lock_acquire(lock)					\
	do {								\
		local_trylock_t *__tl;					\
		local_lock_t *__l;					\
									\
		__l = (local_lock_t *)(lock);				\
		__tl = (local_trylock_t *)__l;				\
		_Generic((lock),					\
			local_trylock_t *: ({				\
				lockdep_assert(__tl->acquired == 0);	\
				WRITE_ONCE(__tl->acquired, 1);		\
			}),						\
			local_lock_t *: (void)0);			\
		local_lock_acquire(__l);				\
	} while (0)

#define __local_lock(lock)					\
	do {							\
		preempt_disable();				\
		__local_lock_acquire(lock);			\
		__acquire(lock);				\
	} while (0)

#define __local_lock_irq(lock)					\
	do {							\
		local_irq_disable();				\
		__local_lock_acquire(lock);			\
		__acquire(lock);				\
	} while (0)

#define __local_lock_irqsave(lock, flags)			\
	do {							\
		local_irq_save(flags);				\
		__local_lock_acquire(lock);			\
		__acquire(lock);				\
	} while (0)

#define __local_trylock(lock)					\
	__try_acquire_ctx_lock(lock, ({				\
		local_trylock_t *__tl;				\
								\
		preempt_disable();				\
		__tl = (lock);					\
		if (READ_ONCE(__tl->acquired)) {		\
			preempt_enable();			\
			__tl = NULL;				\
		} else {					\
			WRITE_ONCE(__tl->acquired, 1);		\
			local_trylock_acquire(			\
				(local_lock_t *)__tl);		\
		}						\
		!!__tl;						\
	}))

Annotation

Implementation Notes