mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
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:
parent
391626bb76
commit
95a2b88990
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue