diff options
| -rw-r--r-- | include/linux/jump_label_ref.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/include/linux/jump_label_ref.h b/include/linux/jump_label_ref.h new file mode 100644 index 000000000000..e5d012ad92c6 --- /dev/null +++ b/include/linux/jump_label_ref.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #ifndef _LINUX_JUMP_LABEL_REF_H | ||
| 2 | #define _LINUX_JUMP_LABEL_REF_H | ||
| 3 | |||
| 4 | #include <linux/jump_label.h> | ||
| 5 | #include <asm/atomic.h> | ||
| 6 | |||
| 7 | #ifdef HAVE_JUMP_LABEL | ||
| 8 | |||
| 9 | static inline void jump_label_inc(atomic_t *key) | ||
| 10 | { | ||
| 11 | if (atomic_add_return(1, key) == 1) | ||
| 12 | jump_label_enable(key); | ||
| 13 | } | ||
| 14 | |||
| 15 | static inline void jump_label_dec(atomic_t *key) | ||
| 16 | { | ||
| 17 | if (atomic_dec_and_test(key)) | ||
| 18 | jump_label_disable(key); | ||
| 19 | } | ||
| 20 | |||
| 21 | #else /* !HAVE_JUMP_LABEL */ | ||
| 22 | |||
| 23 | static inline void jump_label_inc(atomic_t *key) | ||
| 24 | { | ||
| 25 | atomic_inc(key); | ||
| 26 | } | ||
| 27 | |||
| 28 | static inline void jump_label_dec(atomic_t *key) | ||
| 29 | { | ||
| 30 | atomic_dec(key); | ||
| 31 | } | ||
| 32 | |||
| 33 | #undef JUMP_LABEL | ||
| 34 | #define JUMP_LABEL(key, label) \ | ||
| 35 | do { \ | ||
| 36 | if (unlikely(__builtin_choose_expr( \ | ||
| 37 | __builtin_types_compatible_p(typeof(key), atomic_t *), \ | ||
| 38 | atomic_read((atomic_t *)(key)), *(key)))) \ | ||
| 39 | goto label; \ | ||
| 40 | } while (0) | ||
| 41 | |||
| 42 | #endif /* HAVE_JUMP_LABEL */ | ||
| 43 | |||
| 44 | #endif /* _LINUX_JUMP_LABEL_REF_H */ | ||
