Merge "Revert "Revert "Revert "Revert "SharedMemory: break Cleaner reference cycle.""""" into sc-v2-dev
This commit is contained in:
@@ -63,7 +63,7 @@ public final class SharedMemory implements Parcelable, Closeable {
|
||||
|
||||
mMemoryRegistration = new MemoryRegistration(mSize);
|
||||
mCleaner = Cleaner.create(mFileDescriptor,
|
||||
new Closer(mFileDescriptor, mMemoryRegistration));
|
||||
new Closer(mFileDescriptor.getInt$(), mMemoryRegistration));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,6 +256,7 @@ public final class SharedMemory implements Parcelable, Closeable {
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
mFileDescriptor.setInt$(-1);
|
||||
if (mCleaner != null) {
|
||||
mCleaner.clean();
|
||||
mCleaner = null;
|
||||
@@ -305,10 +306,10 @@ public final class SharedMemory implements Parcelable, Closeable {
|
||||
* Cleaner that closes the FD
|
||||
*/
|
||||
private static final class Closer implements Runnable {
|
||||
private FileDescriptor mFd;
|
||||
private int mFd;
|
||||
private MemoryRegistration mMemoryReference;
|
||||
|
||||
private Closer(FileDescriptor fd, MemoryRegistration memoryReference) {
|
||||
private Closer(int fd, MemoryRegistration memoryReference) {
|
||||
mFd = fd;
|
||||
mMemoryReference = memoryReference;
|
||||
}
|
||||
@@ -316,7 +317,9 @@ public final class SharedMemory implements Parcelable, Closeable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Os.close(mFd);
|
||||
FileDescriptor fd = new FileDescriptor();
|
||||
fd.setInt$(mFd);
|
||||
Os.close(fd);
|
||||
} catch (ErrnoException e) { /* swallow error */ }
|
||||
mMemoryReference.release();
|
||||
mMemoryReference = null;
|
||||
|
||||
@@ -73,6 +73,15 @@
|
||||
"[^/]*BatteryConsumer[^/]*\\.java"
|
||||
],
|
||||
"name": "BatteryUsageStatsProtoTests"
|
||||
},
|
||||
{
|
||||
"file_patterns": ["SharedMemory[^/]*\\.java"],
|
||||
"name": "CtsOsTestCases",
|
||||
"options": [
|
||||
{
|
||||
"include-filter": "android.os.cts.SharedMemoryTest"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"postsubmit": [
|
||||
|
||||
Reference in New Issue
Block a user