DanaR: fix message locking

This commit is contained in:
Milos Kozak 2023-08-29 19:13:25 +02:00
parent a7d330e87f
commit f16229c4ed
2 changed files with 9 additions and 10 deletions

View file

@ -33,8 +33,6 @@ public class SerialIOThread extends Thread {
private final MessageHashTableBase hashTable;
private final DanaPump danaPump;
private final Object lock = new Object();
public SerialIOThread(AAPSLogger aapsLogger, BluetoothSocket rfcommSocket, MessageHashTableBase hashTable, DanaPump danaPump) {
super();
this.hashTable = hashTable;
@ -84,7 +82,7 @@ public class SerialIOThread extends Thread {
// process the message content
message.setReceived(true);
message.handleMessage(extractedBuff);
synchronized (lock) {
synchronized (message) {
message.notifyAll();
}
}

View file

@ -40,6 +40,7 @@ import java.util.concurrent.ScheduledFuture
import javax.inject.Inject
import javax.inject.Singleton
@Suppress("SpellCheckingInspection")
@Singleton
class BLECommonService @Inject internal constructor(
private val injector: HasAndroidInjector,
@ -399,15 +400,15 @@ class BLECommonService @Inject internal constructor(
}
}
if (message != null) {
aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + message!!.friendlyName + " " + DiaconnG8Packet.toHex(data))
message?.let {
aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + it.friendlyName + " " + DiaconnG8Packet.toHex(data))
// process received data
message!!.handleMessage(data)
message!!.setReceived()
synchronized(message!!) {
it.handleMessage(data)
it.setReceived()
synchronized(it) {
// notify to sendMessage
message!!.notifyAll()
it.notifyAll()
}
} else aapsLogger.error("Unknown message received " + DiaconnG8Packet.toHex(data))
} ?: aapsLogger.error("Unknown message received " + DiaconnG8Packet.toHex(data))
}
}