[Mesa-dev] [PATCH 2/2] glapi: remove u_mutex wrapper code, use c99 thread mutexes directly

Chia-I Wu olvaffe at gmail.com
Thu Mar 6 19:31:20 PST 2014


On Thu, Mar 6, 2014 at 11:03 PM, Brian Paul <brianp at vmware.com> wrote:
> On 03/05/2014 08:37 PM, Chia-I Wu wrote:
>>
>> On Thu, Mar 6, 2014 at 7:06 AM, Brian Paul <brianp at vmware.com> wrote:
>>>
>>> ---
>>>   src/mapi/mapi.c      |   10 +++++-----
>>>   src/mapi/stub.c      |    6 +++---
>>>   src/mapi/u_current.c |    6 +++---
>>>   src/mapi/u_execmem.c |    6 +++---
>>>   src/mapi/u_thread.h  |   10 ----------
>>>   5 files changed, 14 insertions(+), 24 deletions(-)
>>>
>>> diff --git a/src/mapi/mapi.c b/src/mapi/mapi.c
>>> index 56f209b..8d0baca 100644
>>> --- a/src/mapi/mapi.c
>>> +++ b/src/mapi/mapi.c
>>> @@ -72,15 +72,15 @@ get_stub(const char *name, const struct mapi_stub
>>> *alias)
>>>   void
>>>   mapi_init(const char *spec)
>>>   {
>>> -   u_mutex_declare_static(mutex);
>>> +   static mtx_t mutex = _MTX_INITIALIZER_NP;
>>>      const char *p;
>>>      int ver, count;
>>>
>>> -   u_mutex_lock(mutex);
>>> +   mtx_lock(&mutex);
>>>
>>>      /* already initialized */
>>>      if (mapi_num_stubs) {
>>> -      u_mutex_unlock(mutex);
>>> +      mtx_unlock(&mutex);
>>>         return;
>>>      }
>>>
>>> @@ -90,7 +90,7 @@ mapi_init(const char *spec)
>>>      /* parse version string */
>>>      ver = atoi(p);
>>>      if (ver != 1) {
>>> -      u_mutex_unlock(mutex);
>>> +      mtx_unlock(&mutex);
>>>         return;
>>>      }
>>>      p += strlen(p) + 1;
>>> @@ -115,7 +115,7 @@ mapi_init(const char *spec)
>>>
>>>      mapi_num_stubs = count;
>>>
>>> -   u_mutex_unlock(mutex);
>>> +   mtx_unlock(&mutex);
>>>   }
>>>
>>>   /**
>>> diff --git a/src/mapi/stub.c b/src/mapi/stub.c
>>> index acd2c0a..b5db597 100644
>>> --- a/src/mapi/stub.c
>>> +++ b/src/mapi/stub.c
>>> @@ -126,11 +126,11 @@ stub_add_dynamic(const char *name)
>>>   struct mapi_stub *
>>>   stub_find_dynamic(const char *name, int generate)
>>>   {
>>> -   u_mutex_declare_static(dynamic_mutex);
>>> +   static mtx_t dynamic_mutex = _MTX_INITIALIZER_NP
>>> PTHREAD_MUTEX_INITIALIZER;
>>
>> PTHREAD_MUTEX_INITIALIZER should be dropped.  With that fixed,
>
>
> Got it.  Thanks.  I guess this code didn't get compiled in my current
> configuration.  I'm still trying to figure out all the mapi/ code.  I don't
> yet understand the (four!) different mapi compile modes and when they're
> used.
With --enable-shared-glapi, mapi is compiled twice.  Once in
MAPI_MODE_GLAPI mode, to create libglapi.so, which is an
implementation of glapi.h.  And then once again in MAPI_MODE_BRIDGE
mode, which provides all glFoo() symbols and gets statically linked to
by libGL.so.  Those glFoo() call into libglapi.so to get/set current
dispatch table and etc.

With --disable-shared-glapi, a different implementation of glapi.h and
glFoo() symbols is created and is statically linked to by libGL.so.
In this case, mapi is compiled once in MAPI_MODE_UTIL mode, to provide
u_current and u_execmem utility functions.

The old code, src/mapi/glapi/*.[ch], is used only when
--disable-shared-glapi is given.  It is so because mapi does not have
a replacement for gl_SPARC_asm.py.  Otherwise, we could get rid of the
old code and use mapi everywhere.

>
> -Brian
>

-- 
olv at LunarG.com


More information about the mesa-dev mailing list