Commit 28272aa6 authored by Matej Frančeškin's avatar Matej Frančeškin

Change synchronization object

parent f90b91fe
...@@ -32,6 +32,7 @@ public class TaiSync ...@@ -32,6 +32,7 @@ public class TaiSync
private static final int TAISYNC_SETTINGS_PORT = 8200; private static final int TAISYNC_SETTINGS_PORT = 8200;
private static final int TAISYNC_TELEMETRY_PORT = 8400; private static final int TAISYNC_TELEMETRY_PORT = 8400;
private Object runLock;
private boolean running = false; private boolean running = false;
private DatagramSocket udpSocket = null; private DatagramSocket udpSocket = null;
private Socket tcpSettingsSocket = null; private Socket tcpSettingsSocket = null;
...@@ -49,12 +50,13 @@ public class TaiSync ...@@ -49,12 +50,13 @@ public class TaiSync
public TaiSync() public TaiSync()
{ {
runLock = new Object();
mThreadPool = Executors.newFixedThreadPool(3); mThreadPool = Executors.newFixedThreadPool(3);
} }
public boolean isRunning() public boolean isRunning()
{ {
synchronized (this) { synchronized (runLock) {
return running; return running;
} }
} }
...@@ -63,7 +65,7 @@ public class TaiSync ...@@ -63,7 +65,7 @@ public class TaiSync
{ {
// Log.i("QGC_TaiSync", "Open"); // Log.i("QGC_TaiSync", "Open");
synchronized (this) { synchronized (runLock) {
if (running) { if (running) {
return; return;
} }
...@@ -100,7 +102,7 @@ public class TaiSync ...@@ -100,7 +102,7 @@ public class TaiSync
try { try {
while (bytesRead >= 0) { while (bytesRead >= 0) {
synchronized (this) { synchronized (runLock) {
if (!running) { if (!running) {
break; break;
} }
...@@ -161,7 +163,7 @@ public class TaiSync ...@@ -161,7 +163,7 @@ public class TaiSync
try { try {
while (true) { while (true) {
synchronized (this) { synchronized (runLock) {
if (!running) { if (!running) {
break; break;
} }
...@@ -190,7 +192,7 @@ public class TaiSync ...@@ -190,7 +192,7 @@ public class TaiSync
try { try {
while (true) { while (true) {
synchronized (this) { synchronized (runLock) {
if (!running) { if (!running) {
break; break;
} }
...@@ -209,7 +211,7 @@ public class TaiSync ...@@ -209,7 +211,7 @@ public class TaiSync
} }
} }
}); });
} }
private void sendTaiSyncMessage(byte protocol, int dataPort, byte[] data, int dataLen) throws IOException private void sendTaiSyncMessage(byte protocol, int dataPort, byte[] data, int dataLen) throws IOException
{ {
...@@ -239,7 +241,7 @@ public class TaiSync ...@@ -239,7 +241,7 @@ public class TaiSync
System.arraycopy(data, 0, buffer, header.length, dataLen); System.arraycopy(data, 0, buffer, header.length, dataLen);
} }
synchronized (this) { synchronized (runLock) {
mFileOutputStream.write(buffer); mFileOutputStream.write(buffer);
} }
} }
...@@ -247,7 +249,7 @@ public class TaiSync ...@@ -247,7 +249,7 @@ public class TaiSync
public void close() public void close()
{ {
// Log.i("QGC_TaiSync", "Close"); // Log.i("QGC_TaiSync", "Close");
synchronized (this) { synchronized (runLock) {
running = false; running = false;
} }
try { try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment