summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/qqcache_impl.h
blob: f709b74d6c1e46bc1712e19fd86a86215a32eca7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */

/*
 * Copyright 2018, Joyent, Inc.
 */

#ifndef _QQCACHE_IMPL_H
#define	_QQCACHE_IMPL_H

#include <sys/debug.h>
#include <sys/qqcache.h>

#ifdef __cplusplus
extern "C" {
#endif

#define	QQCACHE_NUM_LISTS 2
#define	QQCACHE_INSERT_LIST 1
#define	QQCACHE_MIN_SIZE 10

CTASSERT(QQCACHE_INSERT_LIST < QQCACHE_NUM_LISTS);
CTASSERT(QQCACHE_NUM_LISTS >= 2);

typedef struct qqcache_list {
	list_t	qqcl_list;
	size_t	qqcl_len;
} qqcache_list_t;

struct qqcache {
	qqcache_hash_fn_t qqc_hash_fn;
	qqcache_cmp_fn_t qqc_cmp_fn;
	qqcache_dtor_fn_t qqc_dtor_fn;
	size_t		qqc_link_off;
	size_t		qqc_tag_off;
	size_t		qqc_nbuckets;
	size_t		qqc_size;
	size_t		qqc_a;
	size_t		qqc_max[QQCACHE_NUM_LISTS];
	qqcache_list_t	qqc_lists[QQCACHE_NUM_LISTS];
	qqcache_list_t	qqc_buckets[];
};

#define	QQCACHE_LIST(qqc, lnk) \
	(&(qqc)->qqc_lists[(lnk)->qqln_listnum])

#ifdef lint
extern qqcache_link_t *obj_to_link(qqcache_t *, void *);
extern void *link_to_obj(qqcache_t *, qqcache_link_t *);
extern void *obj_to_tag(qqcache_t *, void *);
#else
#define	obj_to_link(_q, _o) \
	((qqcache_link_t *)(((char *)(_o)) + (_q)->qqc_link_off))
#define	link_to_obj(_q, _l) \
	((void *)(((char *)(_l)) - (_q)->qqc_link_off))
#define	obj_to_tag(_q, _o) \
	((void *)(((char *)(_o)) + (_q)->qqc_tag_off))
#endif

#ifdef __cplusplus
}
#endif

#endif /* _QQCACHE_IMPL_H */