synchronize on dedicated lock for catchup instead of account

This commit is contained in:
Daniel Gultsch 2017-05-19 13:30:57 +02:00
parent 9fd6539534
commit 7cd4ed78b2
2 changed files with 10 additions and 2 deletions

View File

@ -52,6 +52,8 @@ import eu.siacs.conversations.xmpp.XmppConnection;
public class NotificationService {
public static final Object CATCHUP_LOCK = new Object();
private static final String CONVERSATIONS_GROUP = "eu.siacs.conversations";
private final XmppConnectionService mXmppConnectionService;
@ -173,7 +175,7 @@ public class NotificationService {
}
public void push(final Message message) {
synchronized (message.getConversation().getAccount()) {
synchronized (CATCHUP_LOCK) {
final XmppConnection connection = message.getConversation().getAccount().getXmppConnection();
if (connection.isWaitingForSmCatchup()) {
connection.incrementSmCatchupMessageCounter();

View File

@ -64,6 +64,7 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.ServiceDiscoveryResult;
import eu.siacs.conversations.generator.IqGenerator;
import eu.siacs.conversations.services.NotificationService;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.DNSHelper;
import eu.siacs.conversations.utils.SSLSocketHelper;
@ -617,15 +618,20 @@ public class XmppConnection implements Runnable {
final AckPacket ack = new AckPacket(this.stanzasReceived, smVersion);
tagWriter.writeStanzaAsync(ack);
} else if (nextTag.isStart("a")) {
synchronized (account) {
boolean accountUiNeedsRefresh = false;
synchronized (NotificationService.CATCHUP_LOCK) {
if (mWaitingForSmCatchup.compareAndSet(true, false)) {
int count = mSmCatchupMessageCounter.get();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": SM catchup complete (" + count + ")");
accountUiNeedsRefresh = true;
if (count > 0) {
mXmppConnectionService.getNotificationService().finishBacklog(true, account);
}
}
}
if (accountUiNeedsRefresh) {
mXmppConnectionService.updateAccountUi();
}
final Element ack = tagReader.readElement(nextTag);
lastPacketReceived = SystemClock.elapsedRealtime();
try {