OSDN Git Service

Don't leave gralloc-only host connections hanging.
authorLingfeng Yang <lfy@google.com>
Mon, 13 Jun 2016 15:39:28 +0000 (08:39 -0700)
committerLingfeng Yang <lfy@google.com>
Fri, 17 Jun 2016 14:56:57 +0000 (14:56 +0000)
commit200c716904a03dce573add4440dd6d26c027ea14
treec472067085956be2b7647d5cd7d05e6c999ab303
parentd16ee725a0079357a38d5ea6e5154482642d4650
Don't leave gralloc-only host connections hanging.

bug: 29318455

Memory leaks are becoming more of a problem, especially
with host machines that don't have much RAM and when
we use the emulator for long periods of time.

This CL fixes the problem detailed in the bug link,
which is that the number of render threads
(and thus thread-specific storage) skyrockets when
repeatedly pressing the Recents button while an app is active.

The thing is that there are lots of threads
that never use the EGL display, just gralloc, in order
to do gralloc things like update the screenshot display
of apps in recents.

These threads are not cleaned up because a thread pool
is often used to manage these sorts of tasks.
If a new or different thread suddenly wants to update
the recents screenshots through gralloc, a new connection
will be established.

This CL uses gralloc_unregister_buffer as a signal
for when a thread might be done with gralloc in general,
exiting the host connection immediately.

Of course, there may be other things that the thread wants
to do, but then it can just go ahead and create a new connection.

We also use the heuristic that we do not exit on gralloc_unregister_buffer
when the thread seems to be a bona fide rendering thread
(eglInitialize has been called).

There are still more leaks going on, this fixes just
one source of them.

After this CL, the render thread count should be held constant
when repeatedly starting apps and going to recents.

Change-Id: I5f57539429f149e3a938467e3b82fa911ab118c3
system/OpenglSystemCommon/HostConnection.cpp
system/OpenglSystemCommon/HostConnection.h
system/egl/eglDisplay.cpp
system/gralloc/gralloc.cpp