Loading graphics/java/android/renderscript/RenderScript.java +29 −15 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ package android.renderscript; import java.io.File; import java.lang.reflect.Field; import java.util.concurrent.locks.*; import android.app.ActivityManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; Loading Loading @@ -1048,8 +1050,11 @@ public class RenderScript { RenderScript mRS; boolean mRun = true; int currentSize = 0; final static int targetSize = 256*1024*1024; // call System.gc after 256MB of allocs long currentSize = 0; long targetSize; // call System.gc after 512MB of allocs final Lock lock = new ReentrantLock(); final Condition cond = lock.newCondition(); GCThread(RenderScript rs) { super("RSGCThread"); Loading @@ -1058,29 +1063,37 @@ public class RenderScript { } public void run() { ActivityManager am = (ActivityManager)mRS.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo meminfo = new ActivityManager.MemoryInfo(); am.getMemoryInfo(meminfo); targetSize = (long)(meminfo.totalMem * .5f); while(mRun) { boolean doGC = false; synchronized(this) { if (currentSize >= targetSize) { doGC = true; } } if (doGC == true) { System.gc(); } lock.lock(); try { sleep(1, 0); } catch(InterruptedException e) { cond.awaitUninterruptibly(); } finally { lock.unlock(); } } Log.d(LOG_TAG, "GCThread exiting."); } public synchronized void addAllocSize(int bytes) { public synchronized void addAllocSize(long bytes) { currentSize += bytes; if (currentSize >= targetSize) { lock.lock(); try { cond.signal(); } finally { lock.unlock(); } } } public synchronized void removeAllocSize(int bytes) { public synchronized void removeAllocSize(long bytes) { currentSize -= bytes; } Loading Loading @@ -1192,6 +1205,7 @@ public class RenderScript { nContextDeinitToClient(mContext); mMessageThread.mRun = false; mGCThread.mRun = false; mGCThread.addAllocSize(0); try { mMessageThread.join(); mGCThread.join(); Loading Loading
graphics/java/android/renderscript/RenderScript.java +29 −15 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ package android.renderscript; import java.io.File; import java.lang.reflect.Field; import java.util.concurrent.locks.*; import android.app.ActivityManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; Loading Loading @@ -1048,8 +1050,11 @@ public class RenderScript { RenderScript mRS; boolean mRun = true; int currentSize = 0; final static int targetSize = 256*1024*1024; // call System.gc after 256MB of allocs long currentSize = 0; long targetSize; // call System.gc after 512MB of allocs final Lock lock = new ReentrantLock(); final Condition cond = lock.newCondition(); GCThread(RenderScript rs) { super("RSGCThread"); Loading @@ -1058,29 +1063,37 @@ public class RenderScript { } public void run() { ActivityManager am = (ActivityManager)mRS.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo meminfo = new ActivityManager.MemoryInfo(); am.getMemoryInfo(meminfo); targetSize = (long)(meminfo.totalMem * .5f); while(mRun) { boolean doGC = false; synchronized(this) { if (currentSize >= targetSize) { doGC = true; } } if (doGC == true) { System.gc(); } lock.lock(); try { sleep(1, 0); } catch(InterruptedException e) { cond.awaitUninterruptibly(); } finally { lock.unlock(); } } Log.d(LOG_TAG, "GCThread exiting."); } public synchronized void addAllocSize(int bytes) { public synchronized void addAllocSize(long bytes) { currentSize += bytes; if (currentSize >= targetSize) { lock.lock(); try { cond.signal(); } finally { lock.unlock(); } } } public synchronized void removeAllocSize(int bytes) { public synchronized void removeAllocSize(long bytes) { currentSize -= bytes; } Loading Loading @@ -1192,6 +1205,7 @@ public class RenderScript { nContextDeinitToClient(mContext); mMessageThread.mRun = false; mGCThread.mRun = false; mGCThread.addAllocSize(0); try { mMessageThread.join(); mGCThread.join(); Loading