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 {
activeTelem.join(); // 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) { } 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
handler.post(new Runnable() { // Check handler is not null: if we attempt to disconnect before
@Override // the connect process has completed, handler may be null.
public void run() { if(handler != null){
Looper.myLooper().quit(); handler.post(new Runnable() {
} @Override
}); public void run() {
Looper.myLooper().quit();
}
});
}
if (inputProcessThread != null) { if (inputProcessThread != null) {
inputProcessThread.interrupt(); inputProcessThread.interrupt();