Skip to content

Commit be8fae5

Browse files
committed
WIP
1 parent fc0981b commit be8fae5

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.google.devtools.build.lib.skyframe;
2+
3+
import com.google.devtools.build.lib.actions.Action;
4+
import com.google.devtools.build.lib.actions.Artifact;
5+
import com.google.devtools.build.lib.profiler.SilentCloseable;
6+
import com.google.devtools.build.lib.vfs.OutputService.ActionFileSystemType;
7+
import java.util.concurrent.ConcurrentHashMap;
8+
import java.util.concurrent.locks.ReentrantReadWriteLock;
9+
import javax.annotation.Nullable;
10+
11+
interface RewoundActionSynchronizer {
12+
SilentCloseable lockForRewoundActionBeforePreparation(Action action) throws InterruptedException;
13+
14+
SilentCloseable lockForAnyActionBeforeExecution(Action action) throws InterruptedException;
15+
16+
RewoundActionSynchronizer NOOP =
17+
new RewoundActionSynchronizer() {
18+
@Override
19+
public SilentCloseable lockForRewoundActionBeforePreparation(Action action) {
20+
return () -> {};
21+
}
22+
23+
@Override
24+
public SilentCloseable lockForAnyActionBeforeExecution(Action action) {
25+
return () -> {};
26+
}
27+
};
28+
29+
static RewoundActionSynchronizer create(
30+
boolean rewindingEnabled, ActionFileSystemType actionFileSystemType) {
31+
if (rewindingEnabled && actionFileSystemType.shouldDoEagerActionPrep()) {
32+
return new BazelRewoundActionSynchronizer();
33+
} else {
34+
return NOOP;
35+
}
36+
}
37+
38+
final class BazelRewoundActionSynchronizer implements RewoundActionSynchronizer {
39+
@Nullable private volatile ReentrantReadWriteLock coarseLock = new ReentrantReadWriteLock();
40+
@Nullable private volatile ConcurrentHashMap<Artifact, ReentrantReadWriteLock> fineLocks = null;
41+
42+
private BazelRewoundActionSynchronizer() {}
43+
44+
@Override
45+
public SilentCloseable lockForRewoundActionBeforePreparation(Action action)
46+
throws InterruptedException {
47+
if (coarseLock != null) {
48+
coarseLock.writeLock().lockInterruptibly();
49+
coarseLock = null;
50+
}
51+
return null;
52+
}
53+
54+
@Override
55+
public SilentCloseable lockForAnyActionBeforeExecution(Action action)
56+
throws InterruptedException {
57+
return null;
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)