From 06e2de45fdea2d70cf75271502f8d56ee61fb5f5 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Sun, 6 Aug 2017 23:43:48 +0300 Subject: [PATCH] [vcs-log] use AtomicInteger instead of volatile int --- .../log/data/index/VcsLogPersistentIndex.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPersistentIndex.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPersistentIndex.java index 6dc251b7ab34..d342909dc69f 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPersistentIndex.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPersistentIndex.java @@ -537,8 +537,8 @@ public class VcsLogPersistentIndex implements VcsLogIndex, Disposable { @NotNull private final TIntHashSet myCommits; private final boolean myFull; - public volatile int myNewIndexedCommits; - public volatile int myOldCommits; + @NotNull private final AtomicInteger myNewIndexedCommits = new AtomicInteger(); + @NotNull private final AtomicInteger myOldCommits = new AtomicInteger(); public IndexingRequest(@NotNull VirtualFile root, @NotNull TIntHashSet commits, boolean full) { myRoot = root; @@ -562,7 +562,7 @@ public class VcsLogPersistentIndex implements VcsLogIndex, Disposable { else { IntStream commits = TroveUtil.stream(myCommits).filter(c -> { if (isIndexed(c)) { - myOldCommits++; + myOldCommits.incrementAndGet(); return false; } return true; @@ -601,7 +601,7 @@ public class VcsLogPersistentIndex implements VcsLogIndex, Disposable { myNewIndexedCommits + " commits in " + myRoot.getName()); } else { - int leftCommits = myCommits.size() - myNewIndexedCommits - myOldCommits; + int leftCommits = myCommits.size() - myNewIndexedCommits.get() - myOldCommits.get(); String leftCommitsMessage = (leftCommits > 0) ? ". " + leftCommits + " commits left" : ""; LOG.debug(formattedTime + @@ -613,7 +613,7 @@ public class VcsLogPersistentIndex implements VcsLogIndex, Disposable { } private void scheduleReindex() { - LOG.debug("Schedule reindexing of " + (myCommits.size() - myNewIndexedCommits - myOldCommits) + " commits in " + myRoot.getName()); + LOG.debug("Schedule reindexing of " + (myCommits.size() - myNewIndexedCommits.get() - myOldCommits.get()) + " commits in " + myRoot.getName()); myCommits.forEach(value -> { markForIndexing(value, myRoot); return true; @@ -631,7 +631,7 @@ public class VcsLogPersistentIndex implements VcsLogIndex, Disposable { List hashes = TroveUtil.map(batch, value -> myStorage.getCommitId(value).getHash().asString()); myProviders.get(myRoot).readFullDetails(myRoot, hashes, detail -> { VcsLogPersistentIndex.this.storeDetail(detail); - myNewIndexedCommits++; + myNewIndexedCommits.incrementAndGet(); }, true); displayProgress(indicator); @@ -643,9 +643,8 @@ public class VcsLogPersistentIndex implements VcsLogIndex, Disposable { myProviders.get(myRoot).readAllFullDetails(myRoot, details -> { storeDetail(details); - myNewIndexedCommits++; - if (myNewIndexedCommits % FLUSHED_COMMITS_NUMBER == 0) flush(); + if (myNewIndexedCommits.incrementAndGet() % FLUSHED_COMMITS_NUMBER == 0) flush(); indicator.checkCanceled(); displayProgress(indicator); @@ -653,7 +652,7 @@ public class VcsLogPersistentIndex implements VcsLogIndex, Disposable { } public void displayProgress(@NotNull ProgressIndicator indicator) { - indicator.setFraction(((double)myNewIndexedCommits + myOldCommits) / myCommits.size()); + indicator.setFraction(((double)myNewIndexedCommits.get() + myOldCommits.get()) / myCommits.size()); } @Override