Commit | Line | Data |
---|---|---|
ebabbf58 | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: MIT |
ebabbf58 MD |
3 | * |
4 | * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
5 | * | |
c0c0989a | 6 | * LTTng Bitmap API |
ebabbf58 MD |
7 | */ |
8 | ||
9 | #ifndef _LTTNG_BITMAP_H | |
10 | #define _LTTNG_BITMAP_H | |
11 | ||
12 | #include <urcu/compiler.h> | |
13 | #include <urcu/system.h> | |
14 | #include <urcu/uatomic.h> | |
15 | #include <stdbool.h> | |
16 | ||
17 | static inline void lttng_bitmap_index(unsigned int index, unsigned int *word, | |
18 | unsigned int *bit) | |
19 | { | |
20 | *word = index / CAA_BITS_PER_LONG; | |
21 | *bit = index % CAA_BITS_PER_LONG; | |
22 | } | |
23 | ||
24 | static inline void lttng_bitmap_set_bit(unsigned int index, unsigned long *p) | |
25 | { | |
26 | unsigned int word, bit; | |
27 | unsigned long val; | |
28 | ||
29 | lttng_bitmap_index(index, &word, &bit); | |
30 | val = 1U << bit; | |
31 | uatomic_or(p + word, val); | |
32 | } | |
33 | ||
34 | static inline void lttng_bitmap_clear_bit(unsigned int index, unsigned long *p) | |
35 | { | |
36 | unsigned int word, bit; | |
37 | unsigned long val; | |
38 | ||
39 | lttng_bitmap_index(index, &word, &bit); | |
40 | val = ~(1U << bit); | |
41 | uatomic_and(p + word, val); | |
42 | } | |
43 | ||
44 | static inline bool lttng_bitmap_test_bit(unsigned int index, unsigned long *p) | |
45 | { | |
46 | unsigned int word, bit; | |
47 | ||
48 | lttng_bitmap_index(index, &word, &bit); | |
49 | return (CMM_LOAD_SHARED(p[word]) >> bit) & 0x1; | |
50 | } | |
51 | ||
52 | #endif /* _LTTNG_BITMAP_H */ |