[Mesa-dev] [PATCH] mesa: avoid pthread_mutexes when adjusting object refcounts

Jan Ziak 0xe2.0x9a.0x9b at gmail.com
Thu Oct 20 20:09:17 UTC 2016


On Thu, Oct 20, 2016 at 12:22 AM, Matt Turner <mattst88 at gmail.com> wrote:
> On Wed, Oct 19, 2016 at 1:58 PM, Jan Ziak <0xe2.0x9a.0x9b at gmail.com> wrote:
>> The current git code and the patched code are fully equivalent to each
>> other. In the unpatched code RefCount is always protected by a mutex
>> and the RefCount adjustment region protects just the RefCount (it
>> doesn't protect anything else) - in the patched code RefCount is
>> always adjusted via p_atomic*().
>>
>> Because of this equivalence: If the new code contains a bug then the
>> unpatched code must contain the same bug as well.
>
> That's all well and good, but it's not sufficient and not really how
> we do things. To replace the mutexes around bufferobjs and texobjs
> with atomics would take us *further* from working code.

The patch replaces mutexes around RefCounts with atomics on RefCounts.

Any other data reachable from bufferobj/texobj pointers still needs to
be protected by a mutex (or multiple mutexes if necessary).

Rule: A refcount dropping to zero implies that the refcounted data
(that is: data under the refcount) won't be accessed from the
direction of the refcount.

A refcount dropping to zero can (under certain circumstances) imply
that the refcounted data no longer needs to be protected by a mutex.


More information about the mesa-dev mailing list