1 /******************************************************************************
2  *
3  * Copyright (c) 2009 Citrix Systems, Inc. (Grzegorz Milos)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; If not, see <http://www.gnu.org/licenses/>.
17  */
18 #include "memshr-priv.h"
19 
20 /* Macros used to assemble the names */
21 #define BIDIR_NAME_ONE_INTERNAL(prefix, name) \
22                                 prefix ## _ ## name
23 #define BIDIR_NAME_TWO_INTERNAL(prefix, name1, name2) \
24                                 prefix ## _ ## name1 ## _ ## name2
25 
26 #define BIDIR_NAME_ONE(prefix, name) \
27                                 BIDIR_NAME_ONE_INTERNAL(prefix, name)
28 #define BIDIR_NAME_TWO(prefix, name1, name2) \
29                                 BIDIR_NAME_TWO_INTERNAL(prefix, name1, name2)
30 
31 #define INTERNAL_NAME_ONE(name) BIDIR_NAME_ONE(BIDIR_NAME_PREFIX, name)
32 #define INTERNAL_NAME_TWO(name1, name2) \
33                                 BIDIR_NAME_TWO(BIDIR_NAME_PREFIX, name1, name2)
34 
35 /* Function/type names */
36 #define __k_t                   BIDIR_KEY_T
37 #define __v_t                   BIDIR_VALUE_T
38 
39 #define __hash                  INTERNAL_NAME_ONE(hash)
40 #define __shm_hash_init         INTERNAL_NAME_ONE(shm_hash_init)
41 #define __shm_hash_get          INTERNAL_NAME_ONE(shm_hash_get)
42 #define __hash_init             INTERNAL_NAME_ONE(hash_init)
43 #define __key_lookup            INTERNAL_NAME_TWO(BIDIR_KEY, lookup)
44 #define __value_lookup          INTERNAL_NAME_TWO(BIDIR_VALUE, lookup)
45 #define __insert                INTERNAL_NAME_ONE(insert)
46 #define __key_remove            INTERNAL_NAME_TWO(BIDIR_KEY, remove)
47 #define __value_remove          INTERNAL_NAME_TWO(BIDIR_VALUE, remove)
48 #define __hash_destroy          INTERNAL_NAME_ONE(hash_destroy)
49 #define __hash_iterator         INTERNAL_NAME_ONE(hash_iterator)
50 
51 #define __key_hash              INTERNAL_NAME_TWO(BIDIR_KEY, hash)
52 #define __key_cmp               INTERNAL_NAME_TWO(BIDIR_KEY, cmp)
53 #define __value_hash            INTERNAL_NAME_TWO(BIDIR_VALUE, hash)
54 #define __value_cmp             INTERNAL_NAME_TWO(BIDIR_VALUE, cmp)
55 
56 #define __hash_sizes            INTERNAL_NAME_ONE(hash_sizes)
57 
58 
59 /* Final function exports */
60 struct __hash* __shm_hash_init(unsigned long shm_baddr, unsigned long shm_size);
61 struct __hash* __shm_hash_get(unsigned long shm_baddr);
62 struct __hash *__hash_init   (struct __hash *h, uint32_t min_size);
63 int            __key_lookup  (struct __hash *h, __k_t k, __v_t *vp);
64 int            __value_lookup(struct __hash *h, __v_t v, __k_t *kp);
65 int            __insert      (struct __hash *h, __k_t k, __v_t v);
66 int            __key_remove  (struct __hash *h, __k_t k, __v_t *vp);
67 int            __value_remove(struct __hash *h, __v_t v, __k_t *kp);
68 int            __hash_destroy(struct __hash *h,
69                     void (*entry_consumer)(__k_t k, __v_t v, void *p),
70                     void *d);
71 int            __hash_iterator(struct __hash *h,
72                         int (*entry_consumer)(__k_t k, __v_t v, void *p),
73                         void *d);
74 void           __hash_sizes(struct __hash *h,
75                             uint32_t *nr_ent,
76                             uint32_t *max_nr_ent,
77                             uint32_t *tab_size,
78                             uint32_t *max_load,
79                             uint32_t *min_load);
80