1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-28 06:24:10 +01:00

OP-825 Fix null reference and race condition when shutting down service

This commit is contained in:
David Willis 2013-02-10 01:20:11 +00:00
parent 1d96dfd30e
commit 2f046187ca
2 changed files with 17 additions and 7 deletions

View File

@ -241,7 +241,13 @@ public class OPTelemetryService extends Service {
telemTask = null;
try {
// Race condition - if we shut the service down before the telemetry task
// thread has started, this will hang so we need to check thread is runnable.
if(activeTelem.getState() == Thread.State.RUNNABLE){
activeTelem.join();
}else{
Log.d(TAG, "onDestroy() shut down telemetry task before it has started");
}
} catch (InterruptedException e) {
e.printStackTrace();
}

View File

@ -142,12 +142,16 @@ public abstract class TelemetryTask implements Runnable {
}
// Stop the master telemetry thread
// Check handler is not null: if we attempt to disconnect before
// the connect process has completed, handler may be null.
if(handler != null){
handler.post(new Runnable() {
@Override
public void run() {
Looper.myLooper().quit();
}
});
}
if (inputProcessThread != null) {
inputProcessThread.interrupt();