summaryrefslogtreecommitdiff
path: root/hashmap.h
diff options
context:
space:
mode:
authorJeff Hostetler <jeffhost@microsoft.com>2017-03-22 17:14:22 +0000
committerJunio C Hamano <gitster@pobox.com>2017-03-22 13:41:41 -0700
commit0607e10009ee4e37cb49b4cec8d28a9dda1656a4 (patch)
tree1c4faeee2a69a761d2a6257fa2741750dec43723 /hashmap.h
parentf75619bd6d21760e1da416d4e27bce6468beffcd (diff)
downloadgit-0607e10009ee4e37cb49b4cec8d28a9dda1656a4.tar.gz
hashmap: add disallow_rehash setting
Teach hashmap to allow rehashes to be suppressed. This is useful when hashmaps are accessed by multiple threads. It still requires the caller to properly manage their locking. This just prevents unexpected rehashing during inserts and deletes. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hashmap.h')
-rw-r--r--hashmap.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/hashmap.h b/hashmap.h
index 45eda693bd..de6022a3a9 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -39,6 +39,7 @@ struct hashmap {
struct hashmap_entry **table;
hashmap_cmp_fn cmpfn;
unsigned int size, tablesize, grow_at, shrink_at;
+ unsigned disallow_rehash : 1;
};
struct hashmap_iter {
@@ -77,6 +78,29 @@ static inline void *hashmap_get_from_hash(const struct hashmap *map,
return hashmap_get(map, &key, keydata);
}
+int hashmap_bucket(const struct hashmap *map, unsigned int hash);
+
+/*
+ * Disallow/allow rehashing of the hashmap.
+ * This is useful if the caller knows that the hashmap
+ * needs multi-threaded access. The caller is still
+ * required to guard/lock searches and inserts in a
+ * manner appropriate to their usage. This simply
+ * prevents the table from being unexpectedly re-mapped.
+ *
+ * If is up to the caller to ensure that the hashmap is
+ * initialized to a reasonable size to prevent poor
+ * performance.
+ *
+ * When value=1, prevent future rehashes on adds and deleted.
+ * When value=0, allow future rehahses. This DOES NOT force
+ * a rehash now.
+ */
+static inline void hashmap_disallow_rehash(struct hashmap *map, unsigned value)
+{
+ map->disallow_rehash = value;
+}
+
/* hashmap_iter functions */
extern void hashmap_iter_init(struct hashmap *map, struct hashmap_iter *iter);