Mesa (1020-u_queue-c-173-7-error-implicit-declaration-of-function-timespec_get-is-invalid-in-c99): util/set: split off create() into an init() function
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Jan 14 17:22:51 UTC 2021
Module: Mesa
Branch: 1020-u_queue-c-173-7-error-implicit-declaration-of-function-timespec_get-is-invalid-in-c99
Commit: 184bbef33d1fff3520958c130f2b8e4fce17379c
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=184bbef33d1fff3520958c130f2b8e4fce17379c
Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date: Thu Jan 7 09:39:46 2021 -0500
util/set: split off create() into an init() function
this brings parity with the matching hash_table api
Reviewed-by: Eric Anholt <eric at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8450>
---
src/util/set.c | 31 ++++++++++++++++++++-----------
src/util/set.h | 6 ++++++
2 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/src/util/set.c b/src/util/set.c
index fe945e72dd1..2e3cb92cb00 100644
--- a/src/util/set.c
+++ b/src/util/set.c
@@ -116,18 +116,12 @@ entry_is_present(struct set_entry *entry)
return entry->key != NULL && entry->key != deleted_key;
}
-struct set *
-_mesa_set_create(void *mem_ctx,
+bool
+_mesa_set_init(struct set *ht, void *mem_ctx,
uint32_t (*key_hash_function)(const void *key),
bool (*key_equals_function)(const void *a,
const void *b))
{
- struct set *ht;
-
- ht = ralloc(mem_ctx, struct set);
- if (ht == NULL)
- return NULL;
-
ht->size_index = 0;
ht->size = hash_sizes[ht->size_index].size;
ht->rehash = hash_sizes[ht->size_index].rehash;
@@ -136,11 +130,26 @@ _mesa_set_create(void *mem_ctx,
ht->max_entries = hash_sizes[ht->size_index].max_entries;
ht->key_hash_function = key_hash_function;
ht->key_equals_function = key_equals_function;
- ht->table = rzalloc_array(ht, struct set_entry, ht->size);
+ ht->table = rzalloc_array(mem_ctx, struct set_entry, ht->size);
ht->entries = 0;
ht->deleted_entries = 0;
- if (ht->table == NULL) {
+ return ht->table != NULL;
+}
+
+struct set *
+_mesa_set_create(void *mem_ctx,
+ uint32_t (*key_hash_function)(const void *key),
+ bool (*key_equals_function)(const void *a,
+ const void *b))
+{
+ struct set *ht;
+
+ ht = ralloc(mem_ctx, struct set);
+ if (ht == NULL)
+ return NULL;
+
+ if (!_mesa_set_init(ht, ht, key_hash_function, key_equals_function)) {
ralloc_free(ht);
return NULL;
}
@@ -333,7 +342,7 @@ set_rehash(struct set *ht, unsigned new_size_index)
if (new_size_index >= ARRAY_SIZE(hash_sizes))
return;
- table = rzalloc_array(ht, struct set_entry,
+ table = rzalloc_array(ralloc_parent(ht->table), struct set_entry,
hash_sizes[new_size_index].size);
if (table == NULL)
return;
diff --git a/src/util/set.h b/src/util/set.h
index cabff35dae8..54983138477 100644
--- a/src/util/set.h
+++ b/src/util/set.h
@@ -55,6 +55,12 @@ struct set {
uint32_t deleted_entries;
};
+bool
+_mesa_set_init(struct set *ht, void *mem_ctx,
+ uint32_t (*key_hash_function)(const void *key),
+ bool (*key_equals_function)(const void *a,
+ const void *b));
+
struct set *
_mesa_set_create(void *mem_ctx,
uint32_t (*key_hash_function)(const void *key),
More information about the mesa-commit
mailing list