Add UST default channel creation support
[lttng-tools.git] / lttng-sessiond / hashtable.c
CommitLineData
819dc7d4
DG
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; only version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18#include <urcu.h>
19
20#include <lttng-share.h>
21
22#include "hashtable.h"
23#include "../hashtable/rculfhash.h"
24#include "../hashtable/hash.h"
25
26struct cds_lfht *hashtable_new(unsigned long size)
27{
28 if (size == 0) {
29 size = DEFAULT_HT_SIZE;
30 }
31
32 return cds_lfht_new(hash_key, hash_compare_key, 0x42UL,
48842b30 33 size, size, CDS_LFHT_AUTO_RESIZE, NULL);
819dc7d4
DG
34}
35
36struct cds_lfht *hashtable_new_str(unsigned long size)
37{
38 if (size == 0) {
39 size = DEFAULT_HT_SIZE;
40 }
41
42 return cds_lfht_new(hash_key_str, hash_compare_key_str, 0x42UL,
48842b30 43 size, size, CDS_LFHT_AUTO_RESIZE, NULL);
819dc7d4
DG
44}
45
46struct cds_lfht_node *hashtable_iter_get_node(struct cds_lfht_iter *iter)
47{
48 /* Safety net */
49 if (iter == NULL) {
50 return NULL;
51 }
52
53 return cds_lfht_iter_get_node(iter);
54}
55
56struct cds_lfht_node *hashtable_lookup(struct cds_lfht *ht, void *key,
57 size_t key_len, struct cds_lfht_iter *iter)
58{
59 /* Safety net */
60 if (ht == NULL || iter == NULL || key == NULL) {
61 return NULL;
62 }
63
64 cds_lfht_lookup(ht, key, key_len, iter);
65
66 return hashtable_iter_get_node(iter);
67}
68
69void hashtable_get_first(struct cds_lfht *ht, struct cds_lfht_iter *iter)
70{
71 cds_lfht_first(ht, iter);
72}
73
74void hashtable_get_next(struct cds_lfht *ht, struct cds_lfht_iter *iter)
75{
76 cds_lfht_next(ht, iter);
77}
78
79void hashtable_add_unique(struct cds_lfht *ht, struct cds_lfht_node *node)
80{
81 cds_lfht_add_unique(ht, node);
82}
83
84void hashtable_node_init(struct cds_lfht_node *node, void *key,
85 size_t key_len)
86{
87 cds_lfht_node_init(node, key, key_len);
88}
89
90int hashtable_del(struct cds_lfht *ht, struct cds_lfht_iter *iter)
91{
92 /* Safety net */
93 if (ht == NULL || iter == NULL) {
94 return -1;
95 }
96
97 return cds_lfht_del(ht, iter);
98}
99
100unsigned long hashtable_get_count(struct cds_lfht *ht)
101{
102 long ab, aa;
103 unsigned long count, removed;
104
105 cds_lfht_count_nodes(ht, &ab, &count, &removed, &aa);
106
107 return count;
108}
038238aa
DG
109
110int hashtable_destroy(struct cds_lfht *ht)
111{
112 return cds_lfht_destroy(ht, NULL);
113}
This page took 0.027757 seconds and 4 git commands to generate.