[Mesa-dev] [PATCH v3 05/10] formats: Use a hash table for _mesa_format_from_array_format

Matt Turner mattst88 at gmail.com
Tue Jan 13 20:43:38 PST 2015


On Tue, Jan 13, 2015 at 10:28 AM, Jason Ekstrand <jason at jlekstrand.net> wrote:
> Going through the for loop every time has noticable overhead.  This fixes
> things up so we only do that once ever and then just do a hash table lookup
> which should be much cheaper.
> ---
>  src/mesa/main/formats.c | 67 +++++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 56 insertions(+), 11 deletions(-)
>
> diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
> index 8ac0583..f125a13 100644
> --- a/src/mesa/main/formats.c
> +++ b/src/mesa/main/formats.c
> @@ -28,6 +28,7 @@
>  #include "formats.h"
>  #include "macros.h"
>  #include "glformats.h"
> +#include "util/hash_table.h"
>
>
>  /**
> @@ -377,24 +378,68 @@ _mesa_format_to_array_format(mesa_format format)
>        return _mesa_array_format_flip_channels(info->ArrayFormat);
>  }
>
> +static struct hash_table *format_array_format_table;
> +static pthread_once_t format_array_format_table_exists = PTHREAD_ONCE_INIT;

I meant to suggest that you use the C11 threads API. We have an
implementation in include/c11/ that wraps pthreads.

But, it sounded like what you wanted was for subsequent calls to
format_array_format_table_init() via call_once() to block until the
first had completed. I don't think call_once() does that.
pthread_once() doesn't, at least.

> +
> +static bool
> +array_formats_equal(const void *a, const void *b)
> +{
> +   return (intptr_t)a == (intptr_t)b;

No need to cast.


More information about the mesa-dev mailing list