xref: /freebsd/sys/dev/vmware/vmci/vmci_hashtable.h (revision 4f52dfbb)
1 /*-
2  * Copyright (c) 2018 VMware, Inc.
3  *
4  * SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0)
5  *
6  * $FreeBSD$
7  */
8 
9 /* Hash table for use in the APIs. */
10 
11 #ifndef _VMCI_HASHTABLE_H_
12 #define _VMCI_HASHTABLE_H_
13 
14 #include "vmci_defs.h"
15 #include "vmci_kernel_if.h"
16 
17 struct vmci_hash_entry {
18 	struct vmci_handle	handle;
19 	int			ref_count;
20 	struct vmci_hash_entry	*next;
21 };
22 
23 struct vmci_hashtable {
24 	struct vmci_hash_entry	**entries;
25 	/* Number of buckets in above array. */
26 	int			size;
27 	vmci_lock		lock;
28 };
29 
30 struct	vmci_hashtable *vmci_hashtable_create(int size);
31 void	vmci_hashtable_destroy(struct vmci_hashtable *table);
32 void	vmci_hashtable_init_entry(struct vmci_hash_entry *entry,
33 	    struct vmci_handle handle);
34 int	vmci_hashtable_add_entry(struct vmci_hashtable *table,
35 	    struct vmci_hash_entry *entry);
36 int	vmci_hashtable_remove_entry(struct vmci_hashtable *table,
37 	    struct vmci_hash_entry *entry);
38 struct	vmci_hash_entry *vmci_hashtable_get_entry(struct vmci_hashtable *table,
39 	    struct vmci_handle handle);
40 void	vmci_hashtable_hold_entry(struct vmci_hashtable *table,
41 	    struct vmci_hash_entry *entry);
42 int	vmci_hashtable_release_entry(struct vmci_hashtable *table,
43 	    struct vmci_hash_entry *entry);
44 bool	vmci_hashtable_entry_exists(struct vmci_hashtable *table,
45 	    struct vmci_handle handle);
46 void	vmci_hashtable_sync(struct vmci_hashtable *table);
47 
48 #endif /* !_VMCI_HASHTABLE_H_ */
49