xref: /illumos-gate/usr/src/uts/common/sys/refhash.h (revision 1fa2a66491e7d8ae0be84e7da4da8e812480c710)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2015 Joyent, Inc.
14  */
15 
16 #ifndef	_SYS_REFHASH_H
17 #define	_SYS_REFHASH_H
18 
19 #include <sys/types.h>
20 #include <sys/list.h>
21 
22 #define	RHL_F_DEAD	0x01
23 
24 typedef struct refhash_link {
25 	list_node_t rhl_chain_link;
26 	list_node_t rhl_global_link;
27 	uint_t rhl_flags;
28 	uint_t rhl_refcnt;
29 } refhash_link_t;
30 
31 typedef uint64_t (*refhash_hash_f)(const void *);
32 typedef int (*refhash_cmp_f)(const void *, const void *);
33 typedef void (*refhash_dtor_f)(void *);
34 typedef int (*refhash_eval_f)(const void *, void *);
35 
36 typedef struct refhash {
37 	list_t *rh_buckets;
38 	uint_t rh_bucket_count;
39 	list_t rh_objs;
40 	size_t rh_obj_size;	/* used by mdb */
41 	size_t rh_link_off;
42 	size_t rh_tag_off;
43 	refhash_hash_f rh_hash;
44 	refhash_cmp_f rh_cmp;
45 	refhash_dtor_f rh_dtor;
46 } refhash_t;
47 
48 extern refhash_t *refhash_create(uint_t, refhash_hash_f, refhash_cmp_f,
49     refhash_dtor_f, size_t, size_t, size_t, int);
50 extern void refhash_destroy(refhash_t *);
51 extern void refhash_insert(refhash_t *, void *);
52 extern void refhash_remove(refhash_t *, void *);
53 extern void *refhash_lookup(refhash_t *, const void *);
54 extern void *refhash_linear_search(refhash_t *, refhash_eval_f, void *);
55 extern void refhash_hold(refhash_t *, void *);
56 extern void refhash_rele(refhash_t *, void *);
57 extern void *refhash_first(refhash_t *);
58 extern void *refhash_next(refhash_t *, void *);
59 extern boolean_t refhash_obj_valid(refhash_t *hp, const void *);
60 
61 #endif	/* _SYS_REFHASH_H */
62