1
2 #ifndef _LINUX_ONCE_H
3 #define _LINUX_ONCE_H
4
5 #include <linux/types.h>
6 #include <linux/jump_label.h>
7
8 bool __do_once_start(bool *done, unsigned long *flags);
9 void __do_once_done(bool *done, struct static_key_true *once_key,
10 unsigned long *flags);
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 #define DO_ONCE(func, ...) \
39 ({ \
40 bool ___ret = false; \
41 static bool ___done = false; \
42 static DEFINE_STATIC_KEY_TRUE(___once_key); \
43 if (static_branch_unlikely(&___once_key)) { \
44 unsigned long ___flags; \
45 ___ret = __do_once_start(&___done, &___flags); \
46 if (unlikely(___ret)) { \
47 func(__VA_ARGS__); \
48 __do_once_done(&___done, &___once_key, \
49 &___flags); \
50 } \
51 } \
52 ___ret; \
53 })
54
55 #define get_random_once(buf, nbytes) \
56 DO_ONCE(get_random_bytes, (buf), (nbytes))
57 #define get_random_once_wait(buf, nbytes) \
58 DO_ONCE(get_random_bytes_wait, (buf), (nbytes)) \
59
60 #endif