[Mesa-dev] [PATCH 1/5] util/disk_cache: seed rand

Grazvydas Ignotas notasas at gmail.com
Tue Mar 14 10:34:44 UTC 2017


It's not a good practice to srand() in libraries [1]. Not sure what to
suggest though, maybe rand_r() but "POSIX.1-2008 marks rand_r() as
obsolete". Maybe somebody else (Emil?) has some ideas?

[1] http://stackoverflow.com/questions/14883035/problems-of-using-srand-in-libraries

GraÅžvydas


On Tue, Mar 14, 2017 at 4:08 AM, Timothy Arceri <tarceri at itsqueeze.com> wrote:
> Otherwise we will always remove old cache entries from the same dirs.
> ---
>  src/util/disk_cache.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
> index 2a1024a..dc65d52 100644
> --- a/src/util/disk_cache.c
> +++ b/src/util/disk_cache.c
> @@ -402,20 +402,22 @@ disk_cache_create(const char *gpu_name, const char *timestamp)
>     cache->max_size = max_size;
>
>     /* A limit of 32 jobs was choosen as observations of Deus Ex start-up times
>      * showed that we reached at most 11 jobs on an Intel i5-6400 CPU at 2.70GHz
>      * (a fairly modist desktop CPU). 1 thread was choosen because we don't
>      * really care about getting things to disk quickly just that it's not
>      * blocking other tasks.
>      */
>     util_queue_init(&cache->cache_queue, "disk_cache", 32, 1);
>
> +   srand(time(NULL));
> +
>     ralloc_free(local);
>
>     return cache;
>
>   fail:
>     if (fd != -1)
>        close(fd);
>     if (cache)
>        ralloc_free(cache);
>     ralloc_free(local);
> --
> 2.9.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list