From 155c4c248e6383ffba9942f0c2bc1e6c36a0d09a Mon Sep 17 00:00:00 2001 From: odisseus Date: Tue, 10 Dec 2024 06:39:54 +0100 Subject: [PATCH] Synchronised add and clear --- .../base/qsync/QuerySyncAsyncFileListener.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/base/src/com/google/idea/blaze/base/qsync/QuerySyncAsyncFileListener.java b/base/src/com/google/idea/blaze/base/qsync/QuerySyncAsyncFileListener.java index ea9ab372059..dd23f2880d8 100644 --- a/base/src/com/google/idea/blaze/base/qsync/QuerySyncAsyncFileListener.java +++ b/base/src/com/google/idea/blaze/base/qsync/QuerySyncAsyncFileListener.java @@ -204,16 +204,19 @@ public void afterQuerySync(Project project, BlazeContext context) { @Override public void requestSync(@NotNull Collection files) { logger.info(String.format("Putting %d files into sync queue", files.size())); - unprocessedChanges.addAll(files); - if (changePending.compareAndSet(false, true)) { - if (!BlazeSyncStatus.getInstance(project).syncInProgress()) { - var changesToProcess = ImmutableList.copyOf(unprocessedChanges); - if(!changesToProcess.isEmpty()) { + ImmutableList changesToProcess = ImmutableList.of(); + synchronized (unprocessedChanges) { + unprocessedChanges.addAll(files); + if (changePending.compareAndSet(false, true)) { + if (!BlazeSyncStatus.getInstance(project).syncInProgress()) { + changesToProcess = ImmutableList.copyOf(unprocessedChanges); unprocessedChanges.clear(); - requestSyncInternal(changesToProcess); } } } + if(!changesToProcess.isEmpty()) { + requestSyncInternal(changesToProcess); + } } private void requestSyncInternal(ImmutableCollection files) {