From patchwork Tue Aug 12 21:47:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomas Vestelind X-Patchwork-Id: 152 Return-Path: Received: from mail-la0-f46.google.com (mail-la0-f46.google.com [209.85.215.46]) by dpdk.org (Postfix) with ESMTP id 21D9EB3BE for ; Tue, 12 Aug 2014 23:46:53 +0200 (CEST) Received: by mail-la0-f46.google.com with SMTP id b8so8337077lan.5 for ; Tue, 12 Aug 2014 14:49:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=1GXSX6pw3LftRVt0bulCTPNKSPNzTj7VuoU8e/pIV1Y=; b=cPBv0xlgvmIQ26tYJZgLAwoh+Pgdy9bwLD4M7jvgOxGZCKHPXgwqJ242A9u0e+MAYG 342Is8aZ+irkDC2ku/f21Yu1AUbLVOfoKKlMZFPh616wq60eNv3J3pFK2Rf1yw2xxUkF w//sNiSRMD5mGC+XpyweF4b2HBvf6nFod6iQKzFAGdpx2wZos2iK1G7pSsFA42Klhr5O DrwVXUHrRTU/QlPQdQUnYAjjFeWgPmw/mjFApQk3eyNKGS2j0Qtb+0QSJbGe3aCVClMp ckNX6jhcazbHzLEaLSmYFEvBIaU4j3NJug0ygGlfxg0gFDeTaaaKo4mFKA3Cd97/F9/I Jx6g== X-Received: by 10.152.27.2 with SMTP id p2mr383159lag.23.1407880190106; Tue, 12 Aug 2014 14:49:50 -0700 (PDT) Received: from localhost.localdomain (h-79-136-64-87.na.cust.bahnhof.se. [79.136.64.87]) by mx.google.com with ESMTPSA id o3sm24735915lbh.24.2014.08.12.14.49.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Aug 2014 14:49:49 -0700 (PDT) From: Tomas Vestelind To: dev@dpdk.org Date: Tue, 12 Aug 2014 23:47:57 +0200 Message-Id: <1407880077-15038-1-git-send-email-tomas.vestelind@gmail.com> X-Mailer: git-send-email 1.7.10.4 Subject: [dpdk-dev] [PATCH] hash: added rte_hash_clear that clears all keys X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 21:46:53 -0000 I added rte_hash_clear which clear the map from all previously added keys. Signed-off-by: Tomas Vestelind --- lib/librte_hash/rte_hash.c | 14 ++++++++++++++ lib/librte_hash/rte_hash.h | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/librte_hash/rte_hash.c b/lib/librte_hash/rte_hash.c index 2108c4f..917a6c1 100644 --- a/lib/librte_hash/rte_hash.c +++ b/lib/librte_hash/rte_hash.c @@ -507,3 +507,17 @@ rte_hash_keys(const struct rte_hash *h, void *keys) return found_keys; } + +void +rte_hash_clear(const struct rte_hash *h) +{ + unsigned int bucket, entry; + + /* Clear all entries by invalidating each signature */ + for (bucket = 0; bucket < h->num_buckets; bucket++) { + hash_sig_t *sig = get_sig_tbl_bucket(h, bucket); + for (entry = 0; entry < h->bucket_entries; entry++) { + sig[entry] = NULL_SIGNATURE; + } + } +} diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h index e0fb28f..b84137e 100644 --- a/lib/librte_hash/rte_hash.h +++ b/lib/librte_hash/rte_hash.h @@ -318,6 +318,16 @@ rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys, */ unsigned int rte_hash_keys(const struct rte_hash *h, void *keys); + +/** + * Clear all keys. This operation is not multi-thread safe and should only be + * called from one thread. + * + * @param h + * Hash table to clear. + */ +void +rte_hash_clear(const struct rte_hash *h); #ifdef __cplusplus } #endif