[09/31] batman-adv: hash, Add helper functions
Commit Message
Add helper functions for the hash structure in an attempt to capsulate
the hash struct. It creates a cleaner and more defined interface to the
hashtable and it is more obvious how the hash table is accessed.
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
hash.c | 21 +++++++++++++++++++++
hash.h | 9 +++++++++
2 files changed, 30 insertions(+)
@@ -18,6 +18,27 @@
#include "main.h"
#include "hash.h"
+uint32_t batadv_hash_size(struct batadv_hashtable *hash)
+{
+ return hash->size;
+}
+
+struct hlist_head *batadv_hash_get(struct batadv_hashtable *hash,
+ uint32_t index)
+{
+ return &hash->table[index];
+}
+
+void batadv_hash_lock(struct batadv_hashtable *hash, uint32_t index)
+{
+ spin_lock_bh(&hash->list_locks[index]);
+}
+
+void batadv_hash_unlock(struct batadv_hashtable *hash, uint32_t index)
+{
+ spin_unlock_bh(&hash->list_locks[index]);
+}
+
/* clears the hash */
static void batadv_hash_init(struct batadv_hashtable *hash)
{
@@ -63,4 +63,13 @@ void *batadv_hash_remove(struct batadv_hashtable *hash,
batadv_hashdata_compare_cb compare,
batadv_hashdata_choose_cb choose, void *data);
+uint32_t batadv_hash_size(struct batadv_hashtable *hash);
+
+struct hlist_head *batadv_hash_get(struct batadv_hashtable *hash,
+ uint32_t index);
+
+void batadv_hash_lock(struct batadv_hashtable *hash, uint32_t index);
+
+void batadv_hash_unlock(struct batadv_hashtable *hash, uint32_t index);
+
#endif /* _NET_BATMAN_ADV_HASH_H_ */