Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 844afbc6 authored by Jim Shargo's avatar Jim Shargo
Browse files

Surface: Fix nasty AB-BA deadlocks w/ ConsumerBase::discardFreeBuffers

This change fixes a potential AB-BA deadlock between
Surface::disconnect() or Surface::detachNextBuffer() and
ConsumerBase::discardFreeBuffers().

The deadlock can occur when:

1. A thread calls Surface::disconnect() or Surface::detachNextBuffer(),
   which locks the Surface's mutex and then calls into the
   IGraphicBufferProducer.
2. Another thread calls ConsumerBase::discardFreeBuffers(), which locks
   the ConsumerBase's mutex and then calls into the
   IGraphicBufferConsumer.

These functions each make a call back:

  * Surface::disconnect() and Surface::detachNextBuffer() each call
    ConsumerBase's onBuffersReleased
  * ConsumerBase::discardFreeBuffers() calls Surface's
    onBuffersDiscarded

which each also try to take the respective locks.

This change fixes the deadlock by moving the call to the
IGraphicBufferProducer outside of the Surface's mutex lock in both
Surface::disconnect() and Surface::detachNextBuffer().

Two new tests have been added to Surface_test.cpp to verify the fix.
These tests create a scenario where the deadlock is likely to occur and
assert that the calls complete without deadlocking.

Bug: 436958967
Bug: 437855321
Bug: 438109100
Flag: EXEMPT small fix
Test: new tests deadlock before fixes, work now at 100 iters
Change-Id: I4eb5caacbc9346e53d132c2775b616496df6328b
parent 4c046d36
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment