Fix: sessiond: incorrect use of exclusions array leads to crash
[lttng-tools.git] / src / common / hashtable / hashtable.hpp
CommitLineData
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
c9e313bc 11#include <common/macros.hpp>
28f23191 12
4bd69c5f 13#include <lttng/lttng-export.h>
28f23191
JG
14
15#include <memory>
16#include <stdint.h>
17#include <urcu.h>
8684af09 18#include <urcu/rculfhash.h>
bec39940 19
4bd69c5f 20LTTNG_EXPORT extern unsigned long lttng_ht_seed;
b6314938 21
e665dfbc
JG
22using hash_fct_type = unsigned long (*)(const void *, unsigned long);
23using hash_match_fct = cds_lfht_match_fct;
bec39940
DG
24
25enum lttng_ht_type {
26 LTTNG_HT_TYPE_STRING,
27 LTTNG_HT_TYPE_ULONG,
d88aee68 28 LTTNG_HT_TYPE_U64,
3c4599b9 29 LTTNG_HT_TYPE_TWO_U64,
bec39940
DG
30};
31
aeeb48c6
JG
32struct lttng_ht_deleter;
33
bec39940 34struct lttng_ht {
aeeb48c6 35 using uptr = std::unique_ptr<lttng_ht, lttng_ht_deleter>;
bec39940
DG
36 struct cds_lfht *ht;
37 cds_lfht_match_fct match_fct;
7966af57 38 hash_fct_type hash_fct;
bec39940
DG
39};
40
41struct lttng_ht_iter {
42 struct cds_lfht_iter iter;
43};
44
45struct lttng_ht_node_str {
46 char *key;
47 struct cds_lfht_node node;
48 struct rcu_head head;
49};
50
51struct lttng_ht_node_ulong {
52 unsigned long key;
53 struct cds_lfht_node node;
54 struct rcu_head head;
55};
56
d88aee68
DG
57struct lttng_ht_node_u64 {
58 uint64_t key;
59 struct cds_lfht_node node;
60 struct rcu_head head;
61};
62
3c4599b9
JD
63struct lttng_ht_two_u64 {
64 uint64_t key1;
65 uint64_t key2;
66};
67
68struct lttng_ht_node_two_u64 {
69 struct lttng_ht_two_u64 key;
70 struct cds_lfht_node node;
71 struct rcu_head head;
72};
73
bec39940 74/* Hashtable new and destroy */
6dca8ba7 75struct lttng_ht *lttng_ht_new(unsigned long size, enum lttng_ht_type type);
d604af56 76void lttng_ht_destroy(struct lttng_ht *ht);
aeeb48c6 77struct lttng_ht_deleter {
28f23191
JG
78 void operator()(lttng_ht *ht)
79 {
80 lttng_ht_destroy(ht);
81 };
aeeb48c6 82};
bec39940
DG
83
84/* Specialized node init and free functions */
d604af56 85void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key);
28f23191
JG
86void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node, unsigned long key);
87void lttng_ht_node_init_u64(struct lttng_ht_node_u64 *node, uint64_t key);
88void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64 *node, uint64_t key1, uint64_t key2);
d604af56 89void lttng_ht_node_free_str(struct lttng_ht_node_str *node);
d604af56 90void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node);
d604af56 91void lttng_ht_node_free_u64(struct lttng_ht_node_u64 *node);
d604af56
JG
92void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64 *node);
93
28f23191 94void lttng_ht_lookup(struct lttng_ht *ht, const void *key, struct lttng_ht_iter *iter);
bec39940
DG
95
96/* Specialized add unique functions */
28f23191
JG
97void lttng_ht_add_unique_str(struct lttng_ht *ht, struct lttng_ht_node_str *node);
98void lttng_ht_add_unique_ulong(struct lttng_ht *ht, struct lttng_ht_node_ulong *node);
99void lttng_ht_add_unique_u64(struct lttng_ht *ht, struct lttng_ht_node_u64 *node);
100void lttng_ht_add_unique_two_u64(struct lttng_ht *ht, struct lttng_ht_node_two_u64 *node);
101struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong(struct lttng_ht *ht,
102 struct lttng_ht_node_ulong *node);
103struct lttng_ht_node_u64 *lttng_ht_add_replace_u64(struct lttng_ht *ht,
104 struct lttng_ht_node_u64 *node);
105void lttng_ht_add_str(struct lttng_ht *ht, struct lttng_ht_node_str *node);
106void lttng_ht_add_ulong(struct lttng_ht *ht, struct lttng_ht_node_ulong *node);
107void lttng_ht_add_u64(struct lttng_ht *ht, struct lttng_ht_node_u64 *node);
bec39940 108
d604af56 109int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter);
bec39940 110
28f23191 111void lttng_ht_get_first(struct lttng_ht *ht, struct lttng_ht_iter *iter);
d604af56 112void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter);
bec39940 113
d604af56 114unsigned long lttng_ht_get_count(struct lttng_ht *ht);
bec39940 115
28f23191
JG
116struct lttng_ht_node_str *lttng_ht_iter_get_node_str(struct lttng_ht_iter *iter);
117struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong(struct lttng_ht_iter *iter);
118struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64(struct lttng_ht_iter *iter);
119struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64(struct lttng_ht_iter *iter);
bec39940
DG
120
121#endif /* _LTT_HT_H */
This page took 0.105902 seconds and 4 git commands to generate.