From patchwork Tue Dec 2 11:16:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Pargmann X-Patchwork-Id: 4217 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=92.198.50.35; helo=metis.ext.pengutronix.de; envelope-from=mpa@pengutronix.de; receiver=b.a.t.m.a.n@lists.open-mesh.org Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [92.198.50.35]) by open-mesh.org (Postfix) with ESMTPS id 7239060176A for ; Tue, 2 Dec 2014 12:41:15 +0100 (CET) Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1XvlYQ-0003LK-NI; Tue, 02 Dec 2014 12:23:38 +0100 Received: from mpa by dude.hi.pengutronix.de with local (Exim 4.84) (envelope-from ) id 1XvlYP-0001YY-Ja; Tue, 02 Dec 2014 12:23:37 +0100 From: Markus Pargmann To: Marek Lindner , Simon Wunderlich , Antonio Quartulli Date: Tue, 2 Dec 2014 12:16:27 +0100 Message-Id: <1417519009-20699-10-git-send-email-mpa@pengutronix.de> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1417519009-20699-1-git-send-email-mpa@pengutronix.de> References: <1417519009-20699-1-git-send-email-mpa@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: mpa@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: b.a.t.m.a.n@lists.open-mesh.org Cc: b.a.t.m.a.n@lists.open-mesh.org Subject: [B.A.T.M.A.N.] [PATCH 09/31] batman-adv: hash, Add helper functions X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Dec 2014 11:41:15 -0000 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 --- hash.c | 21 +++++++++++++++++++++ hash.h | 9 +++++++++ 2 files changed, 30 insertions(+) diff --git a/hash.c b/hash.c index c68bb8b3e8b9..d3313b54347c 100644 --- a/hash.c +++ b/hash.c @@ -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) { diff --git a/hash.h b/hash.h index 0761b64be337..d0681ecac0f0 100644 --- a/hash.h +++ b/hash.h @@ -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_ */