0001
0002 #ifndef _LINUX_ONCE_H
0003 #define _LINUX_ONCE_H
0004
0005 #include <linux/types.h>
0006 #include <linux/jump_label.h>
0007
0008 bool __do_once_start(bool *done, unsigned long *flags);
0009 void __do_once_done(bool *done, struct static_key_true *once_key,
0010 unsigned long *flags, struct module *mod);
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #define DO_ONCE(func, ...) \
0039 ({ \
0040 bool ___ret = false; \
0041 static bool __section(".data.once") ___done = false; \
0042 static DEFINE_STATIC_KEY_TRUE(___once_key); \
0043 if (static_branch_unlikely(&___once_key)) { \
0044 unsigned long ___flags; \
0045 ___ret = __do_once_start(&___done, &___flags); \
0046 if (unlikely(___ret)) { \
0047 func(__VA_ARGS__); \
0048 __do_once_done(&___done, &___once_key, \
0049 &___flags, THIS_MODULE); \
0050 } \
0051 } \
0052 ___ret; \
0053 })
0054
0055 #define get_random_once(buf, nbytes) \
0056 DO_ONCE(get_random_bytes, (buf), (nbytes))
0057
0058 #endif