[Mesa-dev] [PATCH 3/8] util/disk_cache: add helpers for creating/destroying disk cache put jobs

Timothy Arceri tarceri at itsqueeze.com
Fri Mar 10 02:28:50 UTC 2017


---
 src/util/disk_cache.c | 28 ++++++++++++++++++++++++++++
 src/util/disk_cache.h | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 426cc55..37b3576 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -727,20 +727,48 @@ deflate_and_write_to_disk(const void *in_data, size_t in_data_size, int dest,
    } while (flush != Z_FINISH);
 
    /* stream should be complete */
    assert(ret == Z_STREAM_END);
 
    /* clean up and return */
    (void)deflateEnd(&strm);
    return compressed_size;
 }
 
+struct disk_cache_put_job *
+disk_cache_create_put_job(struct disk_cache *cache, const cache_key key,
+                          const void *data, size_t size, void *mem)
+{
+   struct disk_cache_put_job *dc_job = (struct disk_cache_put_job *)
+      malloc(sizeof(struct disk_cache_put_job));
+
+   if (dc_job) {
+      dc_job->cache = cache;
+      memcpy(dc_job->key, key, sizeof(cache_key));
+      dc_job->data = data;
+      dc_job->size = size;
+      dc_job->mem = mem;
+   }
+
+   return dc_job;
+}
+
+void
+disk_cache_destroy_put_job(void *job, int thread_index)
+{
+   if (job) {
+      struct disk_cache_put_job *dc_job = (struct disk_cache_put_job *) job;
+      free(dc_job->mem);
+      free(dc_job);
+   }
+}
+
 struct cache_entry_file_data {
    uint32_t crc32;
    uint32_t uncompressed_size;
 };
 
 void
 disk_cache_put(struct disk_cache *cache,
           const cache_key key,
           const void *data,
           size_t size)
diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
index f707ee4..136140e 100644
--- a/src/util/disk_cache.h
+++ b/src/util/disk_cache.h
@@ -38,20 +38,40 @@
 extern "C" {
 #endif
 
 /* Size of cache keys in bytes. */
 #define CACHE_KEY_SIZE 20
 
 typedef uint8_t cache_key[CACHE_KEY_SIZE];
 
 struct disk_cache;
 
+struct disk_cache_put_job {
+   struct util_queue_fence fence;
+
+   struct disk_cache *cache;
+
+   cache_key key;
+
+   /* Cache data to be compressed and written. */
+   const void *data;
+
+   /* Size of data to be compressed and written. */
+   size_t size;
+
+   /* Memory to be freed by util_queue_execute_func cleanup.
+    *
+    * Note: The memory is expected to have been created with ralloc.
+    */
+   void *mem;
+};
+
 static inline const char *
 get_arch_bitness_str(void)
 {
     if (sizeof(void *) == 4)
 #ifdef __ILP32__
         return "ilp-32";
 #else
         return "32";
 #endif
     if (sizeof(void *) == 8)
@@ -119,20 +139,27 @@ disk_cache_create(const char *gpu_name, const char *timestamp);
  */
 void
 disk_cache_destroy(struct disk_cache *cache);
 
 /**
  * Remove the item in the cache under the name \key.
  */
 void
 disk_cache_remove(struct disk_cache *cache, const cache_key key);
 
+struct disk_cache_put_job *
+disk_cache_create_put_job(struct disk_cache *cache, const cache_key key,
+                          const void *data, size_t size, void *mem);
+
+void
+disk_cache_destroy_put_job(void *job, int thread_index);
+
 /**
  * Store an item in the cache under the name \key.
  *
  * The item can be retrieved later with disk_cache_get(), (unless the item has
  * been evicted in the interim).
  *
  * Any call to disk_cache_put() may cause an existing, random item to be
  * evicted from the cache.
  */
 void
@@ -186,20 +213,32 @@ static inline struct disk_cache *
 disk_cache_create(const char *gpu_name, const char *timestamp)
 {
    return NULL;
 }
 
 static inline void
 disk_cache_destroy(struct disk_cache *cache) {
    return;
 }
 
+struct disk_cache_put_job *
+disk_cache_create_put_job(struct disk_cache *cache, const cache_key key,
+                          const void *data, size_t size, void *mem)
+{
+   return NULL;
+}
+
+static inline void
+disk_cache_destroy_put_job(void *job, int thread_index) {
+   return;
+}
+
 static inline void
 disk_cache_put(struct disk_cache *cache, const cache_key key,
           const void *data, size_t size)
 {
    return;
 }
 
 static inline void
 disk_cache_remove(struct disk_cache *cache, const cache_key key)
 {
-- 
2.9.3



More information about the mesa-dev mailing list