| 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 | #ifndef _LTT_HT_H |
| 19 | #define _LTT_HT_H |
| 20 | |
| 21 | #include <urcu.h> |
| 22 | #include "../liblttng-ht/rculfhash.h" |
| 23 | #include "../liblttng-ht/rculfhash-internal.h" |
| 24 | |
| 25 | typedef unsigned long (*hash_fct)(void *_key, unsigned long seed); |
| 26 | typedef cds_lfht_match_fct hash_match_fct; |
| 27 | |
| 28 | enum lttng_ht_type { |
| 29 | LTTNG_HT_TYPE_STRING, |
| 30 | LTTNG_HT_TYPE_ULONG, |
| 31 | }; |
| 32 | |
| 33 | struct lttng_ht { |
| 34 | struct cds_lfht *ht; |
| 35 | cds_lfht_match_fct match_fct; |
| 36 | hash_fct hash_fct; |
| 37 | }; |
| 38 | |
| 39 | struct lttng_ht_iter { |
| 40 | struct cds_lfht_iter iter; |
| 41 | }; |
| 42 | |
| 43 | struct lttng_ht_node_str { |
| 44 | char *key; |
| 45 | struct cds_lfht_node node; |
| 46 | struct rcu_head head; |
| 47 | }; |
| 48 | |
| 49 | struct lttng_ht_node_ulong { |
| 50 | unsigned long key; |
| 51 | struct cds_lfht_node node; |
| 52 | struct rcu_head head; |
| 53 | }; |
| 54 | |
| 55 | /* Hashtable new and destroy */ |
| 56 | extern struct lttng_ht *lttng_ht_new(unsigned long size, int type); |
| 57 | extern void lttng_ht_destroy(struct lttng_ht *ht); |
| 58 | |
| 59 | /* Specialized node init and free functions */ |
| 60 | extern void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key); |
| 61 | extern void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node, |
| 62 | unsigned long key); |
| 63 | extern void lttng_ht_node_free_str(struct lttng_ht_node_str *node); |
| 64 | extern void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node); |
| 65 | |
| 66 | extern void lttng_ht_lookup(struct lttng_ht *ht, void *key, |
| 67 | struct lttng_ht_iter *iter); |
| 68 | |
| 69 | /* Specialized add unique functions */ |
| 70 | extern void lttng_ht_add_unique_str(struct lttng_ht *ht, |
| 71 | struct lttng_ht_node_str *node); |
| 72 | extern void lttng_ht_add_unique_ulong(struct lttng_ht *ht, |
| 73 | struct lttng_ht_node_ulong *node); |
| 74 | |
| 75 | extern int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter); |
| 76 | |
| 77 | extern void lttng_ht_get_first(struct lttng_ht *ht, |
| 78 | struct lttng_ht_iter *iter); |
| 79 | extern void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter); |
| 80 | |
| 81 | extern unsigned long lttng_ht_get_count(struct lttng_ht *ht); |
| 82 | |
| 83 | extern struct lttng_ht_node_str *lttng_ht_iter_get_node_str( |
| 84 | struct lttng_ht_iter *iter); |
| 85 | extern struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong( |
| 86 | struct lttng_ht_iter *iter); |
| 87 | |
| 88 | #endif /* _LTT_HT_H */ |