Skip to content

Commit 155c4c2

Browse files
committed
Synchronised add and clear
1 parent b03028f commit 155c4c2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

base/src/com/google/idea/blaze/base/qsync/QuerySyncAsyncFileListener.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,19 @@ public void afterQuerySync(Project project, BlazeContext context) {
204204
@Override
205205
public void requestSync(@NotNull Collection<VirtualFile> files) {
206206
logger.info(String.format("Putting %d files into sync queue", files.size()));
207-
unprocessedChanges.addAll(files);
208-
if (changePending.compareAndSet(false, true)) {
209-
if (!BlazeSyncStatus.getInstance(project).syncInProgress()) {
210-
var changesToProcess = ImmutableList.copyOf(unprocessedChanges);
211-
if(!changesToProcess.isEmpty()) {
207+
ImmutableList<VirtualFile> changesToProcess = ImmutableList.of();
208+
synchronized (unprocessedChanges) {
209+
unprocessedChanges.addAll(files);
210+
if (changePending.compareAndSet(false, true)) {
211+
if (!BlazeSyncStatus.getInstance(project).syncInProgress()) {
212+
changesToProcess = ImmutableList.copyOf(unprocessedChanges);
212213
unprocessedChanges.clear();
213-
requestSyncInternal(changesToProcess);
214214
}
215215
}
216216
}
217+
if(!changesToProcess.isEmpty()) {
218+
requestSyncInternal(changesToProcess);
219+
}
217220
}
218221

219222
private void requestSyncInternal(ImmutableCollection<VirtualFile> files) {

0 commit comments

Comments
 (0)