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

Grazvydas Ignotas notasas at gmail.com
Mon Mar 13 22:39:51 UTC 2017


On Tue, Mar 14, 2017 at 12:06 AM, Timothy Arceri <tarceri at itsqueeze.com> wrote:
> On 13/03/17 22:55, Grazvydas Ignotas wrote:
>>
>> On Mon, Mar 13, 2017 at 3:01 AM, Timothy Arceri <tarceri at itsqueeze.com>
>> wrote:
>>>
>>> ---
>>>  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)
>>
>>
>> It looks like thread_index is unused by the series.
>>
>
> Right but that's the interface of u_queue, are you suggesting a change? I
> don't think it matters much.

Hmm no, haven't noticed it's in the interface.

GraÅžvydas


More information about the mesa-dev mailing list