1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +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; telemTask = null;
try { 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(); activeTelem.join();
}else{
Log.d(TAG, "onDestroy() shut down telemetry task before it has started");
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -142,12 +142,16 @@ public abstract class TelemetryTask implements Runnable {
} }
// Stop the master telemetry thread // 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() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
Looper.myLooper().quit(); Looper.myLooper().quit();
} }
}); });
}
if (inputProcessThread != null) { if (inputProcessThread != null) {
inputProcessThread.interrupt(); inputProcessThread.interrupt();