system: core: Fix a race condition leading to a fence deadlock

When SurfaceFlinger gets an event that needs a recomposition, it just
asks to be woken up on the next vsync. When it wakes up, it steps
through the list of layers acquiring the next available buffer for each
one (if any) and releasing the previous buffer. Because a new buffer
can become available for a layer asynchronously, it's possible that a
layer might not have a pending buffer when SurfaceFlinger starts
stepping through the list, but does have a pending buffer by the time
SurfaceFlinger gets to that layer.

Buffers incoming to SurfaceFlinger are accompanied by a fence that will
signal when rendering to the buffer is complete. Outgoing buffers are
accompanied by a fence that will signal when the display is done reading
from the buffer -- effectively, when the incoming buffer replaces the
outgoing buffer on screen.

All of that allows deadlock, though the timing and CPU scheduling
events that would cause it to happen are extremely unlikely.

Bug: 15347379
CRs-fixed: 647619
Change-Id: I76a5fc48b4b68a853c99f44a1570307da048b6a9