diff options
author | John Lo <loj@cisco.com> | 2018-01-04 16:39:42 -0500 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2018-01-06 17:34:04 +0000 |
commit | 848b47c70ecfb0bb45636c5c806391848e2878f9 (patch) | |
tree | ff75e417d66930a74aab4346e4a24aa08029ccf4 /src/vppinfra/hash.h | |
parent | 72247c803250894834d15952a6fddcd8f4a39a9c (diff) |
Unify/cleanup usage of hash_set/unset_mem by tunnels (VPP-1117)
Move the functions hash_set_key_copy() and hash_unset_key_free()
which are dupilicated in various tunnel support code modules to
hash.h as hash_set_mem_alloc() and hash_unset_mem_free() to be
used by all.
Change-Id: I40723cabe29072ab7feb1804c221f28606d8e4fe
Signed-off-by: John Lo <loj@cisco.com>
(cherry picked from commit e6bfeab1c352ae73a19361c038e2a06a58c035db)
Diffstat (limited to 'src/vppinfra/hash.h')
-rw-r--r-- | src/vppinfra/hash.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/vppinfra/hash.h b/src/vppinfra/hash.h index 4db5a57602e..6206dd2a486 100644 --- a/src/vppinfra/hash.h +++ b/src/vppinfra/hash.h @@ -273,12 +273,33 @@ uword hash_bytes (void *v); /* Public macro to set (key, value) for pointer key */ #define hash_set_mem(h,key,value) hash_set3 (h, pointer_to_uword (key), (value), 0) +/* Public inline funcion allocate and copy key to use in hash for pointer key */ +always_inline void +hash_set_mem_alloc (uword ** h, void *key, uword v) +{ + size_t ksz = hash_header (*h)->user; + void *copy = clib_mem_alloc (ksz); + clib_memcpy (copy, key, ksz); + hash_set_mem (*h, copy, v); +} + /* Public macro to set (key, 0) for pointer key */ #define hash_set1_mem(h,key) hash_set3 ((h), pointer_to_uword (key), 0, 0) /* Public macro to unset (key, value) for pointer key */ #define hash_unset_mem(h,key) ((h) = _hash_unset ((h), pointer_to_uword (key),0)) +/* Public inline funcion to unset pointer key and then free the key memory */ +always_inline void +hash_unset_mem_free (uword ** h, void *key) +{ + hash_pair_t *hp = hash_get_pair_mem (*h, key); + ASSERT (hp); + key = uword_to_pointer (hp->key, void *); + hash_unset_mem (*h, key); + clib_mem_free (key); +} + /* internal routine to free a hash table */ extern void *_hash_free (void *v); |