OSDN Git Service

SF: Fix a couple of Layer ref count issues
authorDan Stoza <stoza@google.com>
Tue, 9 Aug 2016 20:21:03 +0000 (13:21 -0700)
committerDan Stoza <stoza@google.com>
Thu, 29 Sep 2016 22:33:23 +0000 (15:33 -0700)
commitde84eb6b823ff143f3465ce8f291f1100ce42168
tree7401490a979fd0ac39516fd822fa8472578f743d
parentf9f7f6931f521ddcab6f1f47294cc26326c4be1a
SF: Fix a couple of Layer ref count issues

This is an attempt at fixing two reference counting issues for Layers.

The first issue is that since we were holding an sp<IBinder> (really a
reference to a LayerCleaner) inside the layer state for deferred
transactions, there was a possibility that it could end up being the
last strong reference to the LayerCleaner such that when it was
destroyed while applying a non-deferred transaction, it would attempt
to grab the SurfaceFlinger main lock to destroy its Layer. Since this
occurred in the main SurfaceFlinger loop, which was already holding
the lock to process transactions, this would cause a deadlock.

To fix this, the sp<IBinder> inside the layer state was changed to a
wp<IBinder>, only being promoted when it actually needs to be accessed
(i.e., when the deferred transaction is created).

The second issue is that we were promoting and holding a strong
reference to a Layer before calling into SurfaceFlinger to destroy it
on the onLayerDestroyed path (triggered when a LayerCleaner is
destroyed). After returning from the attempt to grab the SurfaceFlinger
main lock, it was possible that this strong reference was the last one
keeping the Layer alive, and destroying it at this point could cause
the HWC2 version of the layer to be destroyed at effectively any point,
even between validate/present.

To fix this, the promotion of the weak Layer reference was moved inside
the critical section where the SurfaceFlinger main lock is held.

Test: Cherry-pick from internal branch
Bug: 30503916
Bug: 30281222
Change-Id: I1c6a271f9a7b5d6eea9a9db61d971f262d0cfe84
services/surfaceflinger/Client.cpp
services/surfaceflinger/Layer.cpp
services/surfaceflinger/Layer.h
services/surfaceflinger/SurfaceFlinger.cpp
services/surfaceflinger/SurfaceFlinger.h
services/surfaceflinger/SurfaceFlinger_hwc1.cpp