Mesa (main): gallium/util/u_cache: replace simple_list.h with list.h
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Apr 22 17:20:45 UTC 2022
Module: Mesa
Branch: main
Commit: 4ac2503b7a98b6ef4598aad46e4ea67d32d41e9d
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=4ac2503b7a98b6ef4598aad46e4ea67d32d41e9d
Author: Dylan Baker <dylan.c.baker at intel.com>
Date: Wed Feb 16 14:55:51 2022 -0800
gallium/util/u_cache: replace simple_list.h with list.h
Reviewed-by: Roland Scheidegger <sroland at vmware.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15418>
---
src/gallium/auxiliary/util/u_cache.c | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/src/gallium/auxiliary/util/u_cache.c b/src/gallium/auxiliary/util/u_cache.c
index 6c836231b10..69b4e7df2d0 100644
--- a/src/gallium/auxiliary/util/u_cache.c
+++ b/src/gallium/auxiliary/util/u_cache.c
@@ -42,16 +42,14 @@
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_cache.h"
-#include "util/simple_list.h"
-
+#include "util/list.h"
struct util_cache_entry
{
enum { EMPTY = 0, FILLED, DELETED } state;
uint32_t hash;
- struct util_cache_entry *next;
- struct util_cache_entry *prev;
+ struct list_head list;
void *key;
void *value;
@@ -179,7 +177,7 @@ util_cache_entry_destroy(struct util_cache *cache,
entry->value = NULL;
if (entry->state == FILLED) {
- remove_from_list(entry);
+ list_del(&entry->list);
cache->count--;
if (cache->destroy)
@@ -207,10 +205,10 @@ util_cache_set(struct util_cache *cache,
hash = cache->hash(key);
entry = util_cache_entry_get(cache, hash, key);
if (!entry)
- entry = cache->lru.prev;
+ entry = list_last_entry(&cache->lru.list, struct util_cache_entry, list);
if (cache->count >= cache->size / CACHE_DEFAULT_ALPHA)
- util_cache_entry_destroy(cache, cache->lru.prev);
+ util_cache_entry_destroy(cache, list_last_entry(&cache->lru.list, struct util_cache_entry, list));
util_cache_entry_destroy(cache, entry);
@@ -222,7 +220,7 @@ util_cache_set(struct util_cache *cache,
entry->hash = hash;
entry->value = value;
entry->state = FILLED;
- insert_at_head(&cache->lru, entry);
+ list_add(&cache->lru.list, &entry->list);
cache->count++;
ensure_sanity(cache);
@@ -234,7 +232,7 @@ util_cache_set(struct util_cache *cache,
* value or NULL if not found.
*/
void *
-util_cache_get(struct util_cache *cache,
+util_cache_get(struct util_cache *cache,
const void *key)
{
struct util_cache_entry *entry;
@@ -248,9 +246,10 @@ util_cache_get(struct util_cache *cache,
if (!entry)
return NULL;
- if (entry->state == FILLED)
- move_to_head(&cache->lru, entry);
-
+ if (entry->state == FILLED) {
+ list_move_to(&cache->lru.list, &entry->list);
+ }
+
return entry->value;
}
@@ -274,7 +273,7 @@ util_cache_clear(struct util_cache *cache)
}
assert(cache->count == 0);
- assert(is_empty_list(&cache->lru));
+ assert(list_is_empty(&cache->lru.list));
ensure_sanity(cache);
}
@@ -362,16 +361,17 @@ ensure_sanity(const struct util_cache *cache)
assert(cache->size >= cnt);
if (cache->count == 0) {
- assert (is_empty_list(&cache->lru));
+ assert (list_is_empty(&cache->lru.list));
}
else {
- struct util_cache_entry *header = cache->lru.next;
+ struct util_cache_entry *header =
+ LIST_ENTRY(struct util_cache_entry, &cache->lru, list);
assert (header);
- assert (!is_empty_list(&cache->lru));
+ assert (!list_is_empty(&cache->lru.list));
for (i = 0; i < cache->count; i++)
- header = header->next;
+ header = LIST_ENTRY(struct util_cache_entry, &header, list);
assert(header == &cache->lru);
}
More information about the mesa-commit
mailing list