commit 01d34e10a3acc145493f862c9582006f91fe3c93
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Thu Dec 8 12:53:00 2016 +0000

    Fix the 'Save' app so that the saving thread does not run all the time in a tight loop

diff --git a/src/main/java/org/distorted/examples/save/SaveActivity.java b/src/main/java/org/distorted/examples/save/SaveActivity.java
index 265c0a6..c1cc12c 100644
--- a/src/main/java/org/distorted/examples/save/SaveActivity.java
+++ b/src/main/java/org/distorted/examples/save/SaveActivity.java
@@ -75,8 +75,6 @@ public class SaveActivity extends Activity implements SeekBar.OnSeekBarChangeLis
   @Override
   protected void onPause() 
     {
-    SaveWorkerThread.stopSending();
-
     GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.saveSurfaceView);
     view.onPause();
       
@@ -93,7 +91,7 @@ public class SaveActivity extends Activity implements SeekBar.OnSeekBarChangeLis
     GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.saveSurfaceView);
     view.onResume();
 
-    SaveWorkerThread.startSending(this);
+    SaveWorkerThread.create(this);
     }
  
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/examples/save/SaveWorkerThread.java b/src/main/java/org/distorted/examples/save/SaveWorkerThread.java
index 0eb5691..465fb3a 100644
--- a/src/main/java/org/distorted/examples/save/SaveWorkerThread.java
+++ b/src/main/java/org/distorted/examples/save/SaveWorkerThread.java
@@ -37,7 +37,6 @@ class SaveWorkerThread extends Thread
   {
   private static Vector<WorkLoad> mBuffers;
   private static SaveWorkerThread mThis=null;
-  private static volatile boolean mPaused;
   private static WeakReference<Activity> mWeakAct;
 
   private static class WorkLoad
@@ -64,32 +63,16 @@ class SaveWorkerThread extends Thread
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  static void startSending(Activity act)
+  static void create(Activity act)
     {
     mWeakAct = new WeakReference(act);
 
-    mPaused = false;
-
     if( mThis==null )
       {
       mBuffers = new Vector<>();
       mThis = new SaveWorkerThread();
       mThis.start();
       }
-    else
-      {
-      synchronized(mThis)
-        {
-        mThis.notify();
-        }
-      }
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  static void stopSending()
-    {
-    mPaused = true;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -106,13 +89,10 @@ class SaveWorkerThread extends Thread
         process(load);
         }
 
-      if( mPaused )
+      synchronized(mThis)
         {
-        synchronized(mThis)
-          {
-          try  { mThis.wait(); }
-          catch(InterruptedException ex) { }
-          }
+        try  { mThis.wait(); }
+        catch(InterruptedException ex) { }
         }
       }
     }
@@ -123,6 +103,11 @@ class SaveWorkerThread extends Thread
     {
     WorkLoad load = new WorkLoad(buffer,width,height,filename);
     mBuffers.add(load);
+
+    synchronized(mThis)
+      {
+      mThis.notify();
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
