Skip to content

Commit

Permalink
Invoke BlazeSyncPlugin.updateInMemoryState w/o a read lock
Browse files Browse the repository at this point in the history
BlazeSyncPlugin.updateInMemoryState is invoked while a read lock is held. This
makes it harder for the implementations of that extension point to run long
running actions, parts of which may not need the read lock.

This CL moves the acquisition of the read locks to be done inside the implementations,
allowing them to further customize when read locks are acquired in the future.

PiperOrigin-RevId: 374278077
  • Loading branch information
Googler authored and copybara-github committed May 17, 2021
1 parent 05b694f commit a045eab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,17 @@ public void updateInMemoryState(
BlazeProjectData blazeProjectData,
Module workspaceModule,
SyncMode syncMode) {
BlazeAndroidProjectStructureSyncer.updateInMemoryState(
project,
context,
workspaceRoot,
projectViewSet,
blazeProjectData,
workspaceModule,
isAndroidWorkspace(blazeProjectData.getWorkspaceLanguageSettings()));
ApplicationManager.getApplication()
.runReadAction(
() ->
BlazeAndroidProjectStructureSyncer.updateInMemoryState(
project,
context,
workspaceRoot,
projectViewSet,
blazeProjectData,
workspaceModule,
isAndroidWorkspace(blazeProjectData.getWorkspaceLanguageSettings())));
}

@Nullable
Expand Down
32 changes: 13 additions & 19 deletions base/src/com/google/idea/blaze/base/sync/SyncPhaseCoordinator.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import com.google.idea.blaze.base.util.SaveUtil;
import com.google.idea.common.experiments.BoolExperiment;
import com.google.idea.common.util.ConcurrencyUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
Expand Down Expand Up @@ -694,24 +693,19 @@ private static List<TimedEvent> updateInMemoryState(
new TimingScope("UpdateInMemoryState", EventType.Other)
.addScopeListener((events, duration) -> timedEvents.addAll(events)));
context.output(new StatusOutput("Updating in-memory state..."));
ApplicationManager.getApplication()
.runReadAction(
() -> {
Module workspaceModule =
ModuleFinder.getInstance(project)
.findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME);
for (BlazeSyncPlugin blazeSyncPlugin :
BlazeSyncPlugin.EP_NAME.getExtensions()) {
blazeSyncPlugin.updateInMemoryState(
project,
context,
WorkspaceRoot.fromProject(project),
projectViewSet,
blazeProjectData,
workspaceModule,
syncMode);
}
});
Module workspaceModule =
ModuleFinder.getInstance(project)
.findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME);
for (BlazeSyncPlugin blazeSyncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
blazeSyncPlugin.updateInMemoryState(
project,
context,
WorkspaceRoot.fromProject(project),
projectViewSet,
blazeProjectData,
workspaceModule,
syncMode);
}
});
return timedEvents;
}
Expand Down
11 changes: 8 additions & 3 deletions cpp/src/com/google/idea/blaze/cpp/BlazeCSyncPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.idea.blaze.base.scope.scopes.TimingScope.EventType;
import com.google.idea.blaze.base.sync.BlazeSyncPlugin;
import com.google.idea.blaze.base.sync.SyncMode;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import java.util.Set;
Expand Down Expand Up @@ -58,9 +59,13 @@ public void updateInMemoryState(
childContext -> {
childContext.push(new TimingScope("Setup C Workspace", EventType.Other));

BlazeCWorkspace blazeCWorkspace = BlazeCWorkspace.getInstance(project);
blazeCWorkspace.update(
childContext, workspaceRoot, projectViewSet, blazeProjectData, syncMode);
ApplicationManager.getApplication()
.runReadAction(
() -> {
BlazeCWorkspace blazeCWorkspace = BlazeCWorkspace.getInstance(project);
blazeCWorkspace.update(
childContext, workspaceRoot, projectViewSet, blazeProjectData, syncMode);
});
});
}

Expand Down

0 comments on commit a045eab

Please sign in to comment.