Skip to content

Commit

Permalink
Synchronised add and clear
Browse files Browse the repository at this point in the history
  • Loading branch information
odisseus committed Dec 10, 2024
1 parent b03028f commit 155c4c2
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,19 @@ public void afterQuerySync(Project project, BlazeContext context) {
@Override
public void requestSync(@NotNull Collection<VirtualFile> 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<VirtualFile> 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<VirtualFile> files) {
Expand Down

0 comments on commit 155c4c2

Please sign in to comment.