[Mesa-dev] [PATCH 3/4] util/disk_cache: have disk_cache_put() optionally free memory

Grazvydas Ignotas notasas at gmail.com
Mon Mar 13 10:16:47 UTC 2017


On Mon, Mar 13, 2017 at 3:01 AM, Timothy Arceri <tarceri at itsqueeze.com> wrote:
> The following patch will move disk_cache_put() into a thread queue
> so we need to be sure memory is not freed before the thread is
> completed. Here we move responsibility for releasing the memory
> onto the disk cache.

I think this is a fragile interface and very easy to mess up, cache
should just make a copy instead. You already do that at one callsite
anyway.

You could even do that while creating struct disk_cache_put_job to
avoid an extra malloc:

struct disk_cache_put_job {
   ...
   size_t size;
   uint8_t mem[0];
};
...
create_put_job(struct disk_cache *cache, const cache_key key,
               const void *data, size_t size)
{
   struct disk_cache_put_job *dc_job = malloc(sizeof(*dc_job) + size);
   ...
   memcpy(dc_job->mem, data, size);
   ...
}

That's of course just my opinion, I hope somebody (Marek?) joins in.

GraÅžvydas


More information about the mesa-dev mailing list