Blame lib/dynamicsizehash_concurrent.h

Packit 032894
/* Copyright (C) 2000-2019 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
Packit 032894
   Written by Srdan Milakovic <sm108@rice.edu>, 2019.
Packit 032894
   Derived from Ulrich Drepper <drepper@redhat.com>, 2000.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of either
Packit 032894
Packit 032894
     * the GNU Lesser General Public License as published by the Free
Packit 032894
       Software Foundation; either version 3 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or
Packit 032894
Packit 032894
     * the GNU General Public License as published by the Free
Packit 032894
       Software Foundation; either version 2 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or both in parallel, as here.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 032894
   General Public License for more details.
Packit 032894
Packit 032894
   You should have received copies of the GNU General Public License and
Packit 032894
   the GNU Lesser General Public License along with this program.  If
Packit 032894
   not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#include <stddef.h>
Packit 032894
#include <pthread.h>
Packit 032894
#include "atomics.h"
Packit 032894
/* Before including this file the following macros must be defined:
Packit 032894
Packit 032894
   NAME      name of the hash table structure.
Packit 032894
   TYPE      data type of the hash table entries
Packit 032894
Packit 032894
   The following macros if present select features:
Packit 032894
Packit 032894
   ITERATE   iterating over the table entries is possible
Packit 032894
   HASHTYPE  integer type for hash values, default unsigned long int
Packit 032894
 */
Packit 032894
Packit 032894
Packit 032894
Packit 032894
#ifndef HASHTYPE
Packit 032894
# define HASHTYPE unsigned long int
Packit 032894
#endif
Packit 032894
Packit 032894
#ifndef RESIZE_BLOCK_SIZE
Packit 032894
# define RESIZE_BLOCK_SIZE 256
Packit 032894
#endif
Packit 032894
Packit 032894
/* Defined separately.  */
Packit 032894
extern size_t next_prime (size_t seed);
Packit 032894
Packit 032894
Packit 032894
/* Table entry type.  */
Packit 032894
#define _DYNHASHCONENTTYPE(name)       \
Packit 032894
  typedef struct name##_ent         \
Packit 032894
  {                                 \
Packit 032894
    _Atomic(HASHTYPE) hashval;      \
Packit 032894
    atomic_uintptr_t val_ptr;       \
Packit 032894
  } name##_ent
Packit 032894
#define DYNHASHENTTYPE(name) _DYNHASHCONENTTYPE (name)
Packit 032894
DYNHASHENTTYPE (NAME);
Packit 032894
Packit 032894
/* Type of the dynamic hash table data structure.  */
Packit 032894
#define _DYNHASHCONTYPE(name) \
Packit 032894
typedef struct                                     \
Packit 032894
{                                                  \
Packit 032894
  size_t size;                                     \
Packit 032894
  size_t old_size;                                 \
Packit 032894
  atomic_size_t filled;                            \
Packit 032894
  name##_ent *table;                               \
Packit 032894
  name##_ent *old_table;                           \
Packit 032894
  atomic_size_t resizing_state;                    \
Packit 032894
  atomic_size_t next_init_block;                   \
Packit 032894
  atomic_size_t num_initialized_blocks;            \
Packit 032894
  atomic_size_t next_move_block;                   \
Packit 032894
  atomic_size_t num_moved_blocks;                  \
Packit 032894
  pthread_rwlock_t resize_rwl;                     \
Packit 032894
} name
Packit 032894
#define DYNHASHTYPE(name) _DYNHASHCONTYPE (name)
Packit 032894
DYNHASHTYPE (NAME);
Packit 032894
Packit 032894
Packit 032894
Packit 032894
#define _FUNCTIONS(name)                                            \
Packit 032894
/* Initialize the hash table.  */                                   \
Packit 032894
extern int name##_init (name *htab, size_t init_size);              \
Packit 032894
                                                                    \
Packit 032894
/* Free resources allocated for hash table.  */                     \
Packit 032894
extern int name##_free (name *htab);                                \
Packit 032894
                                                                    \
Packit 032894
/* Insert new entry.  */                                            \
Packit 032894
extern int name##_insert (name *htab, HASHTYPE hval, TYPE data);    \
Packit 032894
                                                                    \
Packit 032894
/* Find entry in hash table.  */                                    \
Packit 032894
extern TYPE name##_find (name *htab, HASHTYPE hval);
Packit 032894
#define FUNCTIONS(name) _FUNCTIONS (name)
Packit 032894
FUNCTIONS (NAME)
Packit 032894
Packit 032894
Packit 032894
#ifndef NO_UNDEF
Packit 032894
# undef DYNHASHENTTYPE
Packit 032894
# undef DYNHASHTYPE
Packit 032894
# undef FUNCTIONS
Packit 032894
# undef _FUNCTIONS
Packit 032894
# undef XFUNCTIONS
Packit 032894
# undef _XFUNCTIONS
Packit 032894
# undef NAME
Packit 032894
# undef TYPE
Packit 032894
# undef ITERATE
Packit 032894
# undef COMPARE
Packit 032894
# undef FIRST
Packit 032894
# undef NEXT
Packit 032894
#endif