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

Jason Ekstrand jason at jlekstrand.net
Tue Jan 13 21:45:42 PST 2015


On Tue, Jan 13, 2015 at 8:43 PM, Matt Turner <mattst88 at gmail.com> wrote:

> 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.
>

I must have gotten confused.  I could have swarn the wrappers went in the
other direction.


> 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.
>

If it doesn't guarantee that, then what use is it?  From the pthread_once
man page:

The first call to pthread_once() by any thread in a process, with a given
once_control, shall call the init_routine with no arguments. Subsequent
calls of pthread_once() with the same once_control shall not call the
init_routine.  On return from pthread_once(), init_routine shall have
completed.

Sounds to mee like it guarantees that, regardless of the thread, the
function will have been called by someone by the time your call to
pthread_once completes.


> > +
> > +static bool
> > +array_formats_equal(const void *a, const void *b)
> > +{
> > +   return (intptr_t)a == (intptr_t)b;
>
> No need to cast.
>

Yeah, I can get rid of that.
--Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150113/a4c83e70/attachment-0001.html>


More information about the mesa-dev mailing list