Commit good fix for race condition Daniel noted

git-svn-id: https://zxing.googlecode.com/svn/trunk@1366 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2010-05-15 11:28:43 +00:00
parent 391626bb76
commit 95a2b88990

View file

@ -27,6 +27,7 @@ import android.preference.PreferenceManager;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;
import java.util.concurrent.CountDownLatch;
/** /**
* This thread does all the heavy lifting of decoding the images. * This thread does all the heavy lifting of decoding the images.
@ -40,6 +41,7 @@ final class DecodeThread extends Thread {
private final CaptureActivity activity; private final CaptureActivity activity;
private final Hashtable<DecodeHintType, Object> hints; private final Hashtable<DecodeHintType, Object> hints;
private Handler handler; private Handler handler;
private final CountDownLatch handlerInitLatch;
DecodeThread(CaptureActivity activity, DecodeThread(CaptureActivity activity,
Vector<BarcodeFormat> decodeFormats, Vector<BarcodeFormat> decodeFormats,
@ -47,6 +49,7 @@ final class DecodeThread extends Thread {
ResultPointCallback resultPointCallback) { ResultPointCallback resultPointCallback) {
this.activity = activity; this.activity = activity;
handlerInitLatch = new CountDownLatch(1);
hints = new Hashtable<DecodeHintType, Object>(3); hints = new Hashtable<DecodeHintType, Object>(3);
@ -74,13 +77,19 @@ final class DecodeThread extends Thread {
} }
Handler getHandler() { Handler getHandler() {
try {
handlerInitLatch.await();
} catch (InterruptedException ie) {
// continue?
}
return handler; return handler;
} }
@Override @Override
public void run() { public void run() {
Looper.prepare(); Looper.prepare();
handler = new DecodeHandler(activity, hints); handler = new DecodeHandler(activity, hints);
handlerInitLatch.countDown();
Looper.loop(); Looper.loop();
} }