Commit | Line | Data |
---|---|---|
bec39940 | 1 | /* |
21cf9b6b | 2 | * Copyright (C) 2011 EfficiOS Inc. |
bec39940 | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: GPL-2.0-only |
bec39940 | 5 | * |
bec39940 DG |
6 | */ |
7 | ||
8 | #ifndef _LTT_HT_H | |
9 | #define _LTT_HT_H | |
10 | ||
11 | #include <urcu.h> | |
d88aee68 | 12 | #include <stdint.h> |
aeeb48c6 | 13 | #include <memory> |
10a8a223 | 14 | |
c9e313bc | 15 | #include <common/macros.hpp> |
4bd69c5f | 16 | #include <lttng/lttng-export.h> |
8684af09 | 17 | #include <urcu/rculfhash.h> |
bec39940 | 18 | |
4bd69c5f | 19 | LTTNG_EXPORT extern unsigned long lttng_ht_seed; |
b6314938 | 20 | |
7966af57 | 21 | typedef unsigned long (*hash_fct_type)(const void *_key, unsigned long seed); |
bec39940 DG |
22 | typedef cds_lfht_match_fct hash_match_fct; |
23 | ||
24 | enum lttng_ht_type { | |
25 | LTTNG_HT_TYPE_STRING, | |
26 | LTTNG_HT_TYPE_ULONG, | |
d88aee68 | 27 | LTTNG_HT_TYPE_U64, |
3c4599b9 | 28 | LTTNG_HT_TYPE_TWO_U64, |
bec39940 DG |
29 | }; |
30 | ||
aeeb48c6 JG |
31 | struct lttng_ht_deleter; |
32 | ||
bec39940 | 33 | struct lttng_ht { |
aeeb48c6 | 34 | using uptr = std::unique_ptr<lttng_ht, lttng_ht_deleter>; |
bec39940 DG |
35 | struct cds_lfht *ht; |
36 | cds_lfht_match_fct match_fct; | |
7966af57 | 37 | hash_fct_type hash_fct; |
bec39940 DG |
38 | }; |
39 | ||
40 | struct lttng_ht_iter { | |
41 | struct cds_lfht_iter iter; | |
42 | }; | |
43 | ||
44 | struct lttng_ht_node_str { | |
45 | char *key; | |
46 | struct cds_lfht_node node; | |
47 | struct rcu_head head; | |
48 | }; | |
49 | ||
50 | struct lttng_ht_node_ulong { | |
51 | unsigned long key; | |
52 | struct cds_lfht_node node; | |
53 | struct rcu_head head; | |
54 | }; | |
55 | ||
d88aee68 DG |
56 | struct lttng_ht_node_u64 { |
57 | uint64_t key; | |
58 | struct cds_lfht_node node; | |
59 | struct rcu_head head; | |
60 | }; | |
61 | ||
3c4599b9 JD |
62 | struct lttng_ht_two_u64 { |
63 | uint64_t key1; | |
64 | uint64_t key2; | |
65 | }; | |
66 | ||
67 | struct lttng_ht_node_two_u64 { | |
68 | struct lttng_ht_two_u64 key; | |
69 | struct cds_lfht_node node; | |
70 | struct rcu_head head; | |
71 | }; | |
72 | ||
bec39940 | 73 | /* Hashtable new and destroy */ |
6dca8ba7 | 74 | struct lttng_ht *lttng_ht_new(unsigned long size, enum lttng_ht_type type); |
d604af56 | 75 | void lttng_ht_destroy(struct lttng_ht *ht); |
aeeb48c6 JG |
76 | struct lttng_ht_deleter { |
77 | void operator()(lttng_ht *ht) { lttng_ht_destroy(ht); }; | |
78 | }; | |
bec39940 DG |
79 | |
80 | /* Specialized node init and free functions */ | |
d604af56 | 81 | void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key); |
d604af56 | 82 | void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node, |
bec39940 | 83 | unsigned long key); |
d604af56 | 84 | void lttng_ht_node_init_u64(struct lttng_ht_node_u64 *node, |
d88aee68 | 85 | uint64_t key); |
d604af56 | 86 | void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64 *node, |
3c4599b9 | 87 | uint64_t key1, uint64_t key2); |
d604af56 | 88 | void lttng_ht_node_free_str(struct lttng_ht_node_str *node); |
d604af56 | 89 | void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node); |
d604af56 | 90 | void lttng_ht_node_free_u64(struct lttng_ht_node_u64 *node); |
d604af56 JG |
91 | void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64 *node); |
92 | ||
fb9a95c4 | 93 | void lttng_ht_lookup(struct lttng_ht *ht, const void *key, |
bec39940 DG |
94 | struct lttng_ht_iter *iter); |
95 | ||
96 | /* Specialized add unique functions */ | |
d604af56 | 97 | void lttng_ht_add_unique_str(struct lttng_ht *ht, |
bec39940 | 98 | struct lttng_ht_node_str *node); |
d604af56 | 99 | void lttng_ht_add_unique_ulong(struct lttng_ht *ht, |
bec39940 | 100 | struct lttng_ht_node_ulong *node); |
d604af56 | 101 | void lttng_ht_add_unique_u64(struct lttng_ht *ht, |
d88aee68 | 102 | struct lttng_ht_node_u64 *node); |
d604af56 | 103 | void lttng_ht_add_unique_two_u64(struct lttng_ht *ht, |
3c4599b9 | 104 | struct lttng_ht_node_two_u64 *node); |
d604af56 | 105 | struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong( |
852d0037 | 106 | struct lttng_ht *ht, struct lttng_ht_node_ulong *node); |
d604af56 | 107 | struct lttng_ht_node_u64 *lttng_ht_add_replace_u64( |
d88aee68 | 108 | struct lttng_ht *ht, struct lttng_ht_node_u64 *node); |
d604af56 | 109 | void lttng_ht_add_str(struct lttng_ht *ht, |
efa116c6 | 110 | struct lttng_ht_node_str *node); |
d604af56 | 111 | void lttng_ht_add_ulong(struct lttng_ht *ht, |
aefea3b7 | 112 | struct lttng_ht_node_ulong *node); |
d604af56 | 113 | void lttng_ht_add_u64(struct lttng_ht *ht, |
d88aee68 | 114 | struct lttng_ht_node_u64 *node); |
bec39940 | 115 | |
d604af56 | 116 | int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter); |
bec39940 | 117 | |
d604af56 | 118 | void lttng_ht_get_first(struct lttng_ht *ht, |
bec39940 | 119 | struct lttng_ht_iter *iter); |
d604af56 | 120 | void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter); |
bec39940 | 121 | |
d604af56 | 122 | unsigned long lttng_ht_get_count(struct lttng_ht *ht); |
bec39940 | 123 | |
d604af56 | 124 | struct lttng_ht_node_str *lttng_ht_iter_get_node_str( |
bec39940 | 125 | struct lttng_ht_iter *iter); |
d604af56 | 126 | struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong( |
bec39940 | 127 | struct lttng_ht_iter *iter); |
d604af56 | 128 | struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64( |
d88aee68 | 129 | struct lttng_ht_iter *iter); |
d604af56 | 130 | struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64( |
3c4599b9 | 131 | struct lttng_ht_iter *iter); |
bec39940 DG |
132 | |
133 | #endif /* _LTT_HT_H */ |