b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Markus Pargmann <mpa@pengutronix.de>
To: Marek Lindner <mareklindner@neomailbox.ch>,
	Simon Wunderlich <sw@simonwunderlich.de>,
	Antonio Quartulli <antonio@meshcoding.com>
Cc: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 08/31] batman-adv: hash, remove function implementations from header
Date: Tue,  2 Dec 2014 12:16:26 +0100	[thread overview]
Message-ID: <1417519009-20699-9-git-send-email-mpa@pengutronix.de> (raw)
In-Reply-To: <1417519009-20699-1-git-send-email-mpa@pengutronix.de>

These functions are too big to be implemented as inline functions in the
header file. This patch moves them to the hash c file.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 hash.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hash.h | 141 +++++------------------------------------------------------------
 2 files changed, 142 insertions(+), 131 deletions(-)

diff --git a/hash.c b/hash.c
index 7c1c63080e20..c68bb8b3e8b9 100644
--- a/hash.c
+++ b/hash.c
@@ -37,6 +37,35 @@ void batadv_hash_destroy(struct batadv_hashtable *hash)
 	kfree(hash);
 }
 
+/* remove the hash structure. if hashdata_free_cb != NULL, this function will be
+ * called to remove the elements inside of the hash.  if you don't remove the
+ * elements, memory might be leaked.
+ */
+void batadv_hash_delete(struct batadv_hashtable *hash,
+			batadv_hashdata_free_cb free_cb, void *arg)
+{
+	struct hlist_head *head;
+	struct hlist_node *node, *node_tmp;
+	spinlock_t *list_lock; /* spinlock to protect write access */
+	uint32_t i;
+
+	for (i = 0; i < hash->size; i++) {
+		head = &hash->table[i];
+		list_lock = &hash->list_locks[i];
+
+		spin_lock_bh(list_lock);
+		hlist_for_each_safe(node, node_tmp, head) {
+			hlist_del_rcu(node);
+
+			if (free_cb)
+				free_cb(node, arg);
+		}
+		spin_unlock_bh(list_lock);
+	}
+
+	batadv_hash_destroy(hash);
+}
+
 /* allocates and clears the hash */
 struct batadv_hashtable *batadv_hash_new(uint32_t size)
 {
@@ -74,3 +103,106 @@ void batadv_hash_set_lock_class(struct batadv_hashtable *hash,
 	for (i = 0; i < hash->size; i++)
 		lockdep_set_class(&hash->list_locks[i], key);
 }
+
+/**
+ *	batadv_hash_bytes - hash some bytes and add them to the previous hash
+ *	@hash: previous hash value
+ *	@data: data to be hashed
+ *	@size: number of bytes to be hashed
+ *
+ *	Returns the new hash value.
+ */
+uint32_t batadv_hash_bytes(uint32_t hash, const void *data, uint32_t size)
+{
+	const unsigned char *key = data;
+	int i;
+
+	for (i = 0; i < size; i++) {
+		hash += key[i];
+		hash += (hash << 10);
+		hash ^= (hash >> 6);
+	}
+
+	return hash;
+}
+
+/**
+ *	batadv_hash_add - adds data to the hashtable
+ *	@hash: storage hash table
+ *	@compare: callback to determine if 2 hash elements are identical
+ *	@choose: callback calculating the hash index
+ *	@data: data passed to the aforementioned callbacks as argument
+ *	@data_node: to be added element
+ *
+ *	Returns 0 on success, 1 if the element already is in the hash
+ *	and -1 on error.
+ */
+int batadv_hash_add(struct batadv_hashtable *hash,
+		    batadv_hashdata_compare_cb compare,
+		    batadv_hashdata_choose_cb choose, const void *data,
+		    struct hlist_node *data_node)
+{
+	uint32_t index;
+	int ret = -1;
+	struct hlist_head *head;
+	struct hlist_node *node;
+	spinlock_t *list_lock; /* spinlock to protect write access */
+
+	if (!hash)
+		goto out;
+
+	index = choose(data, hash->size);
+	head = &hash->table[index];
+	list_lock = &hash->list_locks[index];
+
+	spin_lock_bh(list_lock);
+
+	hlist_for_each(node, head) {
+		if (!compare(node, data))
+			continue;
+
+		ret = 1;
+		goto unlock;
+	}
+
+	/* no duplicate found in list, add new element */
+	hlist_add_head_rcu(data_node, head);
+
+	ret = 0;
+
+unlock:
+	spin_unlock_bh(list_lock);
+out:
+	return ret;
+}
+
+/* removes data from hash, if found. returns pointer do data on success, so you
+ * can remove the used structure yourself, or NULL on error .  data could be the
+ * structure you use with just the key filled, we just need the key for
+ * comparing.
+ */
+void *batadv_hash_remove(struct batadv_hashtable *hash,
+			 batadv_hashdata_compare_cb compare,
+			 batadv_hashdata_choose_cb choose, void *data)
+{
+	uint32_t index;
+	struct hlist_node *node;
+	struct hlist_head *head;
+	void *data_save = NULL;
+
+	index = choose(data, hash->size);
+	head = &hash->table[index];
+
+	spin_lock_bh(&hash->list_locks[index]);
+	hlist_for_each(node, head) {
+		if (!compare(node, data))
+			continue;
+
+		data_save = node;
+		hlist_del_rcu(node);
+		break;
+	}
+	spin_unlock_bh(&hash->list_locks[index]);
+
+	return data_save;
+}
diff --git a/hash.h b/hash.h
index 539fc1266793..0761b64be337 100644
--- a/hash.h
+++ b/hash.h
@@ -49,139 +49,18 @@ void batadv_hash_set_lock_class(struct batadv_hashtable *hash,
 /* free only the hashtable and the hash itself. */
 void batadv_hash_destroy(struct batadv_hashtable *hash);
 
-/* remove the hash structure. if hashdata_free_cb != NULL, this function will be
- * called to remove the elements inside of the hash.  if you don't remove the
- * elements, memory might be leaked.
- */
-static inline void batadv_hash_delete(struct batadv_hashtable *hash,
-				      batadv_hashdata_free_cb free_cb,
-				      void *arg)
-{
-	struct hlist_head *head;
-	struct hlist_node *node, *node_tmp;
-	spinlock_t *list_lock; /* spinlock to protect write access */
-	uint32_t i;
-
-	for (i = 0; i < hash->size; i++) {
-		head = &hash->table[i];
-		list_lock = &hash->list_locks[i];
-
-		spin_lock_bh(list_lock);
-		hlist_for_each_safe(node, node_tmp, head) {
-			hlist_del_rcu(node);
-
-			if (free_cb)
-				free_cb(node, arg);
-		}
-		spin_unlock_bh(list_lock);
-	}
-
-	batadv_hash_destroy(hash);
-}
-
-/**
- *	batadv_hash_bytes - hash some bytes and add them to the previous hash
- *	@hash: previous hash value
- *	@data: data to be hashed
- *	@size: number of bytes to be hashed
- *
- *	Returns the new hash value.
- */
-static inline uint32_t batadv_hash_bytes(uint32_t hash, const void *data,
-					 uint32_t size)
-{
-	const unsigned char *key = data;
-	int i;
-
-	for (i = 0; i < size; i++) {
-		hash += key[i];
-		hash += (hash << 10);
-		hash ^= (hash >> 6);
-	}
-	return hash;
-}
-
-/**
- *	batadv_hash_add - adds data to the hashtable
- *	@hash: storage hash table
- *	@compare: callback to determine if 2 hash elements are identical
- *	@choose: callback calculating the hash index
- *	@data: data passed to the aforementioned callbacks as argument
- *	@data_node: to be added element
- *
- *	Returns 0 on success, 1 if the element already is in the hash
- *	and -1 on error.
- */
-static inline int batadv_hash_add(struct batadv_hashtable *hash,
-				  batadv_hashdata_compare_cb compare,
-				  batadv_hashdata_choose_cb choose,
-				  const void *data,
-				  struct hlist_node *data_node)
-{
-	uint32_t index;
-	int ret = -1;
-	struct hlist_head *head;
-	struct hlist_node *node;
-	spinlock_t *list_lock; /* spinlock to protect write access */
-
-	if (!hash)
-		goto out;
-
-	index = choose(data, hash->size);
-	head = &hash->table[index];
-	list_lock = &hash->list_locks[index];
-
-	spin_lock_bh(list_lock);
-
-	hlist_for_each(node, head) {
-		if (!compare(node, data))
-			continue;
-
-		ret = 1;
-		goto unlock;
-	}
-
-	/* no duplicate found in list, add new element */
-	hlist_add_head_rcu(data_node, head);
-
-	ret = 0;
-
-unlock:
-	spin_unlock_bh(list_lock);
-out:
-	return ret;
-}
-
-/* removes data from hash, if found. returns pointer do data on success, so you
- * can remove the used structure yourself, or NULL on error .  data could be the
- * structure you use with just the key filled, we just need the key for
- * comparing.
- */
-static inline void *batadv_hash_remove(struct batadv_hashtable *hash,
-				       batadv_hashdata_compare_cb compare,
-				       batadv_hashdata_choose_cb choose,
-				       void *data)
-{
-	uint32_t index;
-	struct hlist_node *node;
-	struct hlist_head *head;
-	void *data_save = NULL;
-
-	index = choose(data, hash->size);
-	head = &hash->table[index];
+uint32_t batadv_hash_bytes(uint32_t hash, const void *data, uint32_t size);
 
-	spin_lock_bh(&hash->list_locks[index]);
-	hlist_for_each(node, head) {
-		if (!compare(node, data))
-			continue;
+int batadv_hash_add(struct batadv_hashtable *hash,
+		    batadv_hashdata_compare_cb compare,
+		    batadv_hashdata_choose_cb choose, const void *data,
+		    struct hlist_node *data_node);
 
-		data_save = node;
-		hlist_del_rcu(node);
-		break;
-	}
-	spin_unlock_bh(&hash->list_locks[index]);
+void batadv_hash_delete(struct batadv_hashtable *hash,
+			batadv_hashdata_free_cb free_cb, void *arg);
 
-	return data_save;
-}
+void *batadv_hash_remove(struct batadv_hashtable *hash,
+			 batadv_hashdata_compare_cb compare,
+			 batadv_hashdata_choose_cb choose, void *data);
 
 #endif /* _NET_BATMAN_ADV_HASH_H_ */
-- 
2.1.3


  parent reply	other threads:[~2014-12-02 11:16 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-02 11:16 [B.A.T.M.A.N.] [PATCH 00/31] batman-adv: Cleanups Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 01/31] batman-adv: debugfs, avoid compiling for !DEBUG_FS Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 02/31] batman-adv: Separate logging header Markus Pargmann
2014-12-02 15:59   ` Martin Hundebøll
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 03/31] batman-adv: iv_ogm, Reduce code duplication Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 04/31] batman-adv: iv_ogm, divide and round for ring buffer avg Markus Pargmann
2015-01-12 15:52   ` Simon Wunderlich
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 05/31] batman-adv: init, Add some error handling Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 06/31] batman-adv: tvlv realloc, move error handling into if block Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 07/31] batman-adv: split tvlv into a seperate file Markus Pargmann
2014-12-02 11:16 ` Markus Pargmann [this message]
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 09/31] batman-adv: hash, Add helper functions Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 10/31] batman-adv: hash, replace direct hash structure accesses Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 11/31] batman-adv: hash, make struct hashtable private Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 12/31] batman-adv: hash, add used linux headers Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 13/31] batman-adv: Makefile, Sort alphabetically Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 14/31] batman-adv: iv_ogm_iface_enable, direct return values Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 15/31] batman-adv: iv_ogm_aggr_packet, bool return value Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 16/31] batman-adv: iv_ogm_send_to_if, declare char* as const Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 17/31] batman-adv: iv_ogm_can_aggregate, code readability Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 18/31] batman-adv: iv_ogm_orig_update, remove unnecessary brackets Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 19/31] batman-adv: iv_ogm_aggregate_new, simplify error handling Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 20/31] batman-adv: iv_ogm_queue_add, Simplify expressions Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 21/31] batman-adv: iv_ogm_orig_update, style, add missin brackets Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 22/31] batman-adv: iv_ogm, Fix dup_status comment Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 23/31] batman-adv: iv_ogm, fix coding style Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 24/31] batman-adv: iv_ogm, fix comment function name Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 25/31] batman-adv: types, Fix comment on bcast_own Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 26/31] batman-adv: main, Convert is_my_mac() to bool Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 27/31] batman-adv: main, batadv_compare_eth return bool Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 28/31] batman-adv: Remove unnecessary ret variable Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 29/31] batman-adv: Remove unnecessary ret variable in algo_register Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 30/31] batman-adv: packet.h, add some missing includes Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 31/31] batman-adv: types.h, add missing include Markus Pargmann
  -- strict thread matches above, loose matches on Subject: below --
2014-12-02 13:03 [B.A.T.M.A.N.] [PATCH 08/31] batman-adv: hash, remove function implementations from header Sven Eckelmann
2014-12-02 13:53 ` Markus Pargmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1417519009-20699-9-git-send-email-mpa@pengutronix.de \
    --to=mpa@pengutronix.de \
    --cc=antonio@meshcoding.com \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=mareklindner@neomailbox.ch \
    --cc=sw@simonwunderlich.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).