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

Timothy Arceri tarceri at itsqueeze.com
Mon Mar 13 01:01:33 UTC 2017


---
 src/util/disk_cache.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 3b1cffc..160774a 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -71,20 +71,40 @@ struct disk_cache {
    /* Pointer to total size of all objects in cache (within index_mmap) */
    uint64_t *size;
 
    /* Pointer to stored keys, (within index_mmap). */
    uint8_t *stored_keys;
 
    /* Maximum size of all cached objects (in bytes). */
    uint64_t max_size;
 };
 
+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;
+};
+
 /* Create a directory named 'path' if it does not already exist.
  *
  * Returns: 0 if path already exists as a directory or if created.
  *         -1 in all other cases.
  */
 static int
 mkdir_if_needed(const char *path)
 {
    struct stat sb;
 
@@ -728,20 +748,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;
 }
 
+static struct disk_cache_put_job *
+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;
+}
+
+static void
+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)
-- 
2.9.3



More information about the mesa-dev mailing list