0001
0002 #ifndef _LINUX_ONCE_LITE_H
0003 #define _LINUX_ONCE_LITE_H
0004
0005 #include <linux/types.h>
0006
0007
0008
0009
0010 #define DO_ONCE_LITE(func, ...) \
0011 DO_ONCE_LITE_IF(true, func, ##__VA_ARGS__)
0012
0013 #define __ONCE_LITE_IF(condition) \
0014 ({ \
0015 static bool __section(".data.once") __already_done; \
0016 bool __ret_cond = !!(condition); \
0017 bool __ret_once = false; \
0018 \
0019 if (unlikely(__ret_cond && !__already_done)) { \
0020 __already_done = true; \
0021 __ret_once = true; \
0022 } \
0023 unlikely(__ret_once); \
0024 })
0025
0026 #define DO_ONCE_LITE_IF(condition, func, ...) \
0027 ({ \
0028 bool __ret_do_once = !!(condition); \
0029 \
0030 if (__ONCE_LITE_IF(__ret_do_once)) \
0031 func(__VA_ARGS__); \
0032 \
0033 unlikely(__ret_do_once); \
0034 })
0035
0036 #endif