include/linux/once.h

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

File Facts

System
Linux kernel
Corpus path
include/linux/once.h
Extension
.h
Size
2726 bytes
Lines
87
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

if (static_branch_unlikely(&___once_key)) {		     \
			unsigned long ___flags;				     \
			___ret = __do_once_start(&___done, &___flags);	     \
			if (unlikely(___ret)) {				     \
				func(__VA_ARGS__);			     \
				__do_once_done(&___done, &___once_key,	     \
					       &___flags, THIS_MODULE);	     \
			}						     \
		}							     \
		___ret;							     \
	})

/* Variant of DO_ONCE() for process/sleepable contexts. */
#define DO_ONCE_SLEEPABLE(func, ...)						\
	({									\
		bool ___ret = false;						\
		static bool __section(".data..do_once") ___done = false;	\
		static DEFINE_STATIC_KEY_TRUE(___once_key);			\
		if (static_branch_unlikely(&___once_key)) {			\
			___ret = __do_once_sleepable_start(&___done);		\
			if (unlikely(___ret)) {					\
				func(__VA_ARGS__);				\
				__do_once_sleepable_done(&___done, &___once_key,\
						    THIS_MODULE);		\
			}							\
		}								\
		___ret;								\
	})

#define get_random_once(buf, nbytes)					     \
	DO_ONCE(get_random_bytes, (buf), (nbytes))

#define get_random_sleepable_once(buf, nbytes)				     \
	DO_ONCE_SLEEPABLE(get_random_bytes, (buf), (nbytes))

#endif /* _LINUX_ONCE_H */

Annotation

Implementation Notes