Methods Summary |
---|
public void | end()Gracefully ends this thread. Will stop after all jobs are processed.
synchronized (mIsEnded) {
mIsEnded = true;
}
synchronized(mJobQueue) {
mJobQueue.notifyAll();
}
|
private boolean | isEnded()
synchronized (mIsEnded) {
return mIsEnded;
}
|
public void | run()
while(true) {
Runnable job = null;
synchronized (mJobQueue) {
while (mJobQueue.size() == 0 && !isEnded()) {
try {
mJobQueue.wait();
} catch (InterruptedException ex) {
Log.w(TAG, "Dispatcher thread wait() interrupted, exiting");
break;
}
}
job = mJobQueue.poll();
}
if (job == null) {
// mJobQueue.poll() returning null means wait() is
// interrupted and the queue is empty.
if (isEnded()) {
break;
}
continue;
}
job.run();
synchronized (DispatchThread.this) {
mCameraHandler.post(new Runnable() {
@Override
public void run() {
synchronized (DispatchThread.this) {
DispatchThread.this.notifyAll();
}
}
});
try {
DispatchThread.this.wait();
} catch (InterruptedException ex) {
// TODO: do something here.
}
}
}
mCameraHandlerThread.quitSafely();
|
public void | runJob(java.lang.Runnable job)Queues up the job.
if (isEnded()) {
throw new IllegalStateException(
"Trying to run job on interrupted dispatcher thread");
}
synchronized (mJobQueue) {
if (mJobQueue.size() == MAX_MESSAGE_QUEUE_LENGTH) {
throw new RuntimeException("Camera master thread job queue full");
}
mJobQueue.add(job);
mJobQueue.notifyAll();
}
|
public void | runJobSync(java.lang.Runnable job, java.lang.Object waitLock, long timeoutMs, java.lang.String jobMsg)Queues up the job and wait for it to be done.
String timeoutMsg = "Timeout waiting " + timeoutMs + "ms for " + jobMsg;
synchronized (waitLock) {
long timeoutBound = SystemClock.uptimeMillis() + timeoutMs;
try {
runJob(job);
waitLock.wait(timeoutMs);
if (SystemClock.uptimeMillis() > timeoutBound) {
throw new IllegalStateException(timeoutMsg);
}
} catch (InterruptedException ex) {
if (SystemClock.uptimeMillis() > timeoutBound) {
throw new IllegalStateException(timeoutMsg);
}
}
}
|