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