xref: /aosp_15_r20/external/elfutils/lib/dynamicsizehash_concurrent.h (revision 7304104da70ce23c86437a01be71edd1a2d7f37e)
1*7304104dSAndroid Build Coastguard Worker /* Copyright (C) 2000-2019 Red Hat, Inc.
2*7304104dSAndroid Build Coastguard Worker    This file is part of elfutils.
3*7304104dSAndroid Build Coastguard Worker    Written by Srdan Milakovic <[email protected]>, 2019.
4*7304104dSAndroid Build Coastguard Worker    Derived from Ulrich Drepper <[email protected]>, 2000.
5*7304104dSAndroid Build Coastguard Worker 
6*7304104dSAndroid Build Coastguard Worker    This file is free software; you can redistribute it and/or modify
7*7304104dSAndroid Build Coastguard Worker    it under the terms of either
8*7304104dSAndroid Build Coastguard Worker 
9*7304104dSAndroid Build Coastguard Worker      * the GNU Lesser General Public License as published by the Free
10*7304104dSAndroid Build Coastguard Worker        Software Foundation; either version 3 of the License, or (at
11*7304104dSAndroid Build Coastguard Worker        your option) any later version
12*7304104dSAndroid Build Coastguard Worker 
13*7304104dSAndroid Build Coastguard Worker    or
14*7304104dSAndroid Build Coastguard Worker 
15*7304104dSAndroid Build Coastguard Worker      * the GNU General Public License as published by the Free
16*7304104dSAndroid Build Coastguard Worker        Software Foundation; either version 2 of the License, or (at
17*7304104dSAndroid Build Coastguard Worker        your option) any later version
18*7304104dSAndroid Build Coastguard Worker 
19*7304104dSAndroid Build Coastguard Worker    or both in parallel, as here.
20*7304104dSAndroid Build Coastguard Worker 
21*7304104dSAndroid Build Coastguard Worker    elfutils is distributed in the hope that it will be useful, but
22*7304104dSAndroid Build Coastguard Worker    WITHOUT ANY WARRANTY; without even the implied warranty of
23*7304104dSAndroid Build Coastguard Worker    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24*7304104dSAndroid Build Coastguard Worker    General Public License for more details.
25*7304104dSAndroid Build Coastguard Worker 
26*7304104dSAndroid Build Coastguard Worker    You should have received copies of the GNU General Public License and
27*7304104dSAndroid Build Coastguard Worker    the GNU Lesser General Public License along with this program.  If
28*7304104dSAndroid Build Coastguard Worker    not, see <http://www.gnu.org/licenses/>.  */
29*7304104dSAndroid Build Coastguard Worker 
30*7304104dSAndroid Build Coastguard Worker #include <stddef.h>
31*7304104dSAndroid Build Coastguard Worker #include <pthread.h>
32*7304104dSAndroid Build Coastguard Worker #include "atomics.h"
33*7304104dSAndroid Build Coastguard Worker /* Before including this file the following macros must be defined:
34*7304104dSAndroid Build Coastguard Worker 
35*7304104dSAndroid Build Coastguard Worker    NAME      name of the hash table structure.
36*7304104dSAndroid Build Coastguard Worker    TYPE      data type of the hash table entries
37*7304104dSAndroid Build Coastguard Worker 
38*7304104dSAndroid Build Coastguard Worker    The following macros if present select features:
39*7304104dSAndroid Build Coastguard Worker 
40*7304104dSAndroid Build Coastguard Worker    ITERATE   iterating over the table entries is possible
41*7304104dSAndroid Build Coastguard Worker    HASHTYPE  integer type for hash values, default unsigned long int
42*7304104dSAndroid Build Coastguard Worker  */
43*7304104dSAndroid Build Coastguard Worker 
44*7304104dSAndroid Build Coastguard Worker 
45*7304104dSAndroid Build Coastguard Worker 
46*7304104dSAndroid Build Coastguard Worker #ifndef HASHTYPE
47*7304104dSAndroid Build Coastguard Worker # define HASHTYPE unsigned long int
48*7304104dSAndroid Build Coastguard Worker #endif
49*7304104dSAndroid Build Coastguard Worker 
50*7304104dSAndroid Build Coastguard Worker #ifndef RESIZE_BLOCK_SIZE
51*7304104dSAndroid Build Coastguard Worker # define RESIZE_BLOCK_SIZE 256
52*7304104dSAndroid Build Coastguard Worker #endif
53*7304104dSAndroid Build Coastguard Worker 
54*7304104dSAndroid Build Coastguard Worker /* Defined separately.  */
55*7304104dSAndroid Build Coastguard Worker extern size_t next_prime (size_t seed);
56*7304104dSAndroid Build Coastguard Worker 
57*7304104dSAndroid Build Coastguard Worker 
58*7304104dSAndroid Build Coastguard Worker /* Table entry type.  */
59*7304104dSAndroid Build Coastguard Worker #define _DYNHASHCONENTTYPE(name)       \
60*7304104dSAndroid Build Coastguard Worker   typedef struct name##_ent         \
61*7304104dSAndroid Build Coastguard Worker   {                                 \
62*7304104dSAndroid Build Coastguard Worker     _Atomic(HASHTYPE) hashval;      \
63*7304104dSAndroid Build Coastguard Worker     atomic_uintptr_t val_ptr;       \
64*7304104dSAndroid Build Coastguard Worker   } name##_ent
65*7304104dSAndroid Build Coastguard Worker #define DYNHASHENTTYPE(name) _DYNHASHCONENTTYPE (name)
66*7304104dSAndroid Build Coastguard Worker DYNHASHENTTYPE (NAME);
67*7304104dSAndroid Build Coastguard Worker 
68*7304104dSAndroid Build Coastguard Worker /* Type of the dynamic hash table data structure.  */
69*7304104dSAndroid Build Coastguard Worker #define _DYNHASHCONTYPE(name) \
70*7304104dSAndroid Build Coastguard Worker typedef struct                                     \
71*7304104dSAndroid Build Coastguard Worker {                                                  \
72*7304104dSAndroid Build Coastguard Worker   size_t size;                                     \
73*7304104dSAndroid Build Coastguard Worker   size_t old_size;                                 \
74*7304104dSAndroid Build Coastguard Worker   atomic_size_t filled;                            \
75*7304104dSAndroid Build Coastguard Worker   name##_ent *table;                               \
76*7304104dSAndroid Build Coastguard Worker   name##_ent *old_table;                           \
77*7304104dSAndroid Build Coastguard Worker   atomic_size_t resizing_state;                    \
78*7304104dSAndroid Build Coastguard Worker   atomic_size_t next_init_block;                   \
79*7304104dSAndroid Build Coastguard Worker   atomic_size_t num_initialized_blocks;            \
80*7304104dSAndroid Build Coastguard Worker   atomic_size_t next_move_block;                   \
81*7304104dSAndroid Build Coastguard Worker   atomic_size_t num_moved_blocks;                  \
82*7304104dSAndroid Build Coastguard Worker   pthread_rwlock_t resize_rwl;                     \
83*7304104dSAndroid Build Coastguard Worker } name
84*7304104dSAndroid Build Coastguard Worker #define DYNHASHTYPE(name) _DYNHASHCONTYPE (name)
85*7304104dSAndroid Build Coastguard Worker DYNHASHTYPE (NAME);
86*7304104dSAndroid Build Coastguard Worker 
87*7304104dSAndroid Build Coastguard Worker 
88*7304104dSAndroid Build Coastguard Worker 
89*7304104dSAndroid Build Coastguard Worker #define _FUNCTIONS(name)                                            \
90*7304104dSAndroid Build Coastguard Worker /* Initialize the hash table.  */                                   \
91*7304104dSAndroid Build Coastguard Worker extern int name##_init (name *htab, size_t init_size);              \
92*7304104dSAndroid Build Coastguard Worker                                                                     \
93*7304104dSAndroid Build Coastguard Worker /* Free resources allocated for hash table.  */                     \
94*7304104dSAndroid Build Coastguard Worker extern int name##_free (name *htab);                                \
95*7304104dSAndroid Build Coastguard Worker                                                                     \
96*7304104dSAndroid Build Coastguard Worker /* Insert new entry.  */                                            \
97*7304104dSAndroid Build Coastguard Worker extern int name##_insert (name *htab, HASHTYPE hval, TYPE data);    \
98*7304104dSAndroid Build Coastguard Worker                                                                     \
99*7304104dSAndroid Build Coastguard Worker /* Find entry in hash table.  */                                    \
100*7304104dSAndroid Build Coastguard Worker extern TYPE name##_find (name *htab, HASHTYPE hval);
101*7304104dSAndroid Build Coastguard Worker #define FUNCTIONS(name) _FUNCTIONS (name)
102*7304104dSAndroid Build Coastguard Worker FUNCTIONS (NAME)
103*7304104dSAndroid Build Coastguard Worker 
104*7304104dSAndroid Build Coastguard Worker 
105*7304104dSAndroid Build Coastguard Worker #ifndef NO_UNDEF
106*7304104dSAndroid Build Coastguard Worker # undef DYNHASHENTTYPE
107*7304104dSAndroid Build Coastguard Worker # undef DYNHASHTYPE
108*7304104dSAndroid Build Coastguard Worker # undef FUNCTIONS
109*7304104dSAndroid Build Coastguard Worker # undef _FUNCTIONS
110*7304104dSAndroid Build Coastguard Worker # undef XFUNCTIONS
111*7304104dSAndroid Build Coastguard Worker # undef _XFUNCTIONS
112*7304104dSAndroid Build Coastguard Worker # undef NAME
113*7304104dSAndroid Build Coastguard Worker # undef TYPE
114*7304104dSAndroid Build Coastguard Worker # undef ITERATE
115*7304104dSAndroid Build Coastguard Worker # undef COMPARE
116*7304104dSAndroid Build Coastguard Worker # undef FIRST
117*7304104dSAndroid Build Coastguard Worker # undef NEXT
118*7304104dSAndroid Build Coastguard Worker #endif
119