Mesa (master): mesa: add _mesa_HashFindFreeKeys

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Sep 10 07:34:39 UTC 2020


Module: Mesa
Branch: master
Commit: 60ffadcbc0715ef736a81f5a4c2b5924cd8b04f6
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=60ffadcbc0715ef736a81f5a4c2b5924cd8b04f6

Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Date:   Mon Aug 17 15:10:31 2020 +0200

mesa: add _mesa_HashFindFreeKeys

_mesa_HashFindFreeKeyBlock function returns a name range, so it cannot be
used to recycle non-consecutive names.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6600>

---

 src/mesa/main/hash.c | 19 +++++++++++++++++++
 src/mesa/main/hash.h |  3 +++
 2 files changed, 22 insertions(+)

diff --git a/src/mesa/main/hash.c b/src/mesa/main/hash.c
index e0d71dad3bf..2f36fc84425 100644
--- a/src/mesa/main/hash.c
+++ b/src/mesa/main/hash.c
@@ -446,6 +446,25 @@ _mesa_HashFindFreeKeyBlock(struct _mesa_HashTable *table, GLuint numKeys)
 }
 
 
+bool
+_mesa_HashFindFreeKeys(struct _mesa_HashTable *table, GLuint* keys, GLuint numKeys)
+{
+   if (!table->id_alloc) {
+      GLuint first = _mesa_HashFindFreeKeyBlock(table, numKeys);
+      for (int i = 0; i < numKeys; i++) {
+         keys[i] = first + i;
+      }
+      return first != 0;
+   }
+
+   for (int i = 0; i < numKeys; i++) {
+      keys[i] = util_idalloc_alloc(table->id_alloc);
+   }
+
+   return true;
+}
+
+
 /**
  * Return the number of entries in the hash table.
  */
diff --git a/src/mesa/main/hash.h b/src/mesa/main/hash.h
index a0411651384..98647674467 100644
--- a/src/mesa/main/hash.h
+++ b/src/mesa/main/hash.h
@@ -178,6 +178,9 @@ extern void _mesa_HashPrint(const struct _mesa_HashTable *table);
 
 extern GLuint _mesa_HashFindFreeKeyBlock(struct _mesa_HashTable *table, GLuint numKeys);
 
+extern bool
+_mesa_HashFindFreeKeys(struct _mesa_HashTable *table, GLuint* keys, GLuint numKeys);
+
 extern GLuint
 _mesa_HashNumEntries(const struct _mesa_HashTable *table);
 



More information about the mesa-commit mailing list