1#ifndef _LINUX_ONCE_H
2#define _LINUX_ONCE_H
3
4#include <linux/types.h>
5#include <linux/jump_label.h>
6
7bool __do_once_start(bool *done, unsigned long *flags);
8void __do_once_done(bool *done, struct static_key *once_key,
9 unsigned long *flags);
10
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#define DO_ONCE(func, ...) \
38 ({ \
39 bool ___ret = false; \
40 static bool ___done = false; \
41 static struct static_key ___once_key = STATIC_KEY_INIT_TRUE; \
42 if (static_key_true(&___once_key)) { \
43 unsigned long ___flags; \
44 ___ret = __do_once_start(&___done, &___flags); \
45 if (unlikely(___ret)) { \
46 func(__VA_ARGS__); \
47 __do_once_done(&___done, &___once_key, \
48 &___flags); \
49 } \
50 } \
51 ___ret; \
52 })
53
54#define get_random_once(buf, nbytes) \
55 DO_ONCE(get_random_bytes, (buf), (nbytes))
56
57#endif
58