2 * Copyright (C) 2011 EfficiOS Inc.
4 * SPDX-License-Identifier: GPL-2.0-only
11 #include <common/macros.hpp>
13 #include <lttng/lttng-export.h>
18 #include <urcu/rculfhash.h>
20 LTTNG_EXPORT extern unsigned long lttng_ht_seed;
22 using hash_fct_type = unsigned long (*)(const void *, unsigned long);
23 using hash_match_fct = cds_lfht_match_fct;
29 LTTNG_HT_TYPE_TWO_U64,
32 struct lttng_ht_deleter;
35 using uptr = std::unique_ptr<lttng_ht, lttng_ht_deleter>;
37 cds_lfht_match_fct match_fct;
38 hash_fct_type hash_fct;
41 struct lttng_ht_iter {
42 struct cds_lfht_iter iter;
45 struct lttng_ht_node_str {
47 struct cds_lfht_node node;
51 struct lttng_ht_node_ulong {
53 struct cds_lfht_node node;
57 struct lttng_ht_node_u64 {
59 struct cds_lfht_node node;
63 struct lttng_ht_two_u64 {
68 struct lttng_ht_node_two_u64 {
69 struct lttng_ht_two_u64 key;
70 struct cds_lfht_node node;
74 /* Hashtable new and destroy */
75 struct lttng_ht *lttng_ht_new(unsigned long size, enum lttng_ht_type type);
76 void lttng_ht_destroy(struct lttng_ht *ht);
77 struct lttng_ht_deleter {
78 void operator()(lttng_ht *ht)
84 /* Specialized node init and free functions */
85 void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key);
86 void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node, unsigned long key);
87 void lttng_ht_node_init_u64(struct lttng_ht_node_u64 *node, uint64_t key);
88 void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64 *node, uint64_t key1, uint64_t key2);
89 void lttng_ht_node_free_str(struct lttng_ht_node_str *node);
90 void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node);
91 void lttng_ht_node_free_u64(struct lttng_ht_node_u64 *node);
92 void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64 *node);
94 void lttng_ht_lookup(struct lttng_ht *ht, const void *key, struct lttng_ht_iter *iter);
96 /* Specialized add unique functions */
97 void lttng_ht_add_unique_str(struct lttng_ht *ht, struct lttng_ht_node_str *node);
98 void lttng_ht_add_unique_ulong(struct lttng_ht *ht, struct lttng_ht_node_ulong *node);
99 void lttng_ht_add_unique_u64(struct lttng_ht *ht, struct lttng_ht_node_u64 *node);
100 void lttng_ht_add_unique_two_u64(struct lttng_ht *ht, struct lttng_ht_node_two_u64 *node);
101 struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong(struct lttng_ht *ht,
102 struct lttng_ht_node_ulong *node);
103 struct lttng_ht_node_u64 *lttng_ht_add_replace_u64(struct lttng_ht *ht,
104 struct lttng_ht_node_u64 *node);
105 void lttng_ht_add_str(struct lttng_ht *ht, struct lttng_ht_node_str *node);
106 void lttng_ht_add_ulong(struct lttng_ht *ht, struct lttng_ht_node_ulong *node);
107 void lttng_ht_add_u64(struct lttng_ht *ht, struct lttng_ht_node_u64 *node);
109 int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter);
111 void lttng_ht_get_first(struct lttng_ht *ht, struct lttng_ht_iter *iter);
112 void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter);
114 unsigned long lttng_ht_get_count(struct lttng_ht *ht);
116 struct lttng_ht_node_str *lttng_ht_iter_get_node_str(struct lttng_ht_iter *iter);
117 struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong(struct lttng_ht_iter *iter);
118 struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64(struct lttng_ht_iter *iter);
119 struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64(struct lttng_ht_iter *iter);
121 #endif /* _LTT_HT_H */