Use one lock for DispatchThread mutable variables

Previously this file included code that used a variable to type
Boolean to synchronize upon, but the object referenced by the variable
changes when the value is toggled from false to true so the
synchronization was incorrect. This is because Boolean objects are not
mutable.

Bug: N/A
Test: Treehugger
Change-Id: Ib9c48d41eb198120a8d0cc956516d4656e104182
diff --git a/camera2/portability/src/com/android/ex/camera2/portability/DispatchThread.java b/camera2/portability/src/com/android/ex/camera2/portability/DispatchThread.java
index bc77259..bf9e6b1 100644
--- a/camera2/portability/src/com/android/ex/camera2/portability/DispatchThread.java
+++ b/camera2/portability/src/com/android/ex/camera2/portability/DispatchThread.java
@@ -22,6 +22,7 @@
 
 import com.android.ex.camera2.portability.debug.Log;
 
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.LinkedList;
 import java.util.Queue;
 
@@ -30,14 +31,14 @@
     private static final long MAX_MESSAGE_QUEUE_LENGTH = 256;
 
     private final Queue<Runnable> mJobQueue;
-    private Boolean mIsEnded;
+    private AtomicBoolean mIsEnded;
     private Handler mCameraHandler;
     private HandlerThread mCameraHandlerThread;
 
     public DispatchThread(Handler cameraHandler, HandlerThread cameraHandlerThread) {
         super("Camera Job Dispatch Thread");
         mJobQueue = new LinkedList<Runnable>();
-        mIsEnded = new Boolean(false);
+        mIsEnded = new AtomicBoolean(false);
         mCameraHandler = cameraHandler;
         mCameraHandlerThread = cameraHandlerThread;
     }
@@ -92,18 +93,14 @@
      * Gracefully ends this thread. Will stop after all jobs are processed.
      */
     public void end() {
-        synchronized (mIsEnded) {
-            mIsEnded = true;
-        }
+        mIsEnded.set(true);
         synchronized(mJobQueue) {
             mJobQueue.notifyAll();
         }
     }
 
     private boolean isEnded() {
-        synchronized (mIsEnded) {
-            return mIsEnded;
-        }
+        return mIsEnded.get();
     }
 
     @Override