aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/skyframe/ThinNodeEntry.java
blob: 1ef077c103cf125cf7e434fa3986b2b71a9eec04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2015 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.skyframe;

import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.util.Preconditions;
import javax.annotation.Nullable;

/**
 * A node in the graph without the means to access its value. All operations on this class are
 * thread-safe. Note, however, the warning on the return value of {@link #markDirty}.
 *
 * <p>This interface is public only for the benefit of alternative graph implementations outside of
 * the package.
 */
public interface ThinNodeEntry {

  /** Returns whether the entry has been built and is finished evaluating. */
  @ThreadSafe
  boolean isDone();

  /**
   * Returns true if the entry is marked dirty, meaning that at least one of its transitive
   * dependencies is marked changed.
   */
  @ThreadSafe
  boolean isDirty();

  /**
   * Returns true if the entry is marked changed, meaning that it must be re-evaluated even if its
   * dependencies' values have not changed.
   */
  @ThreadSafe
  boolean isChanged();

  /**
   * Marks this node dirty, or changed if {@code isChanged} is true. The node is put in the
   * just-created state. It will be re-evaluated if necessary during the evaluation phase, but if it
   * has not changed, it will not force a re-evaluation of its parents.
   *
   * <p>{@code markDirty(b)} must not be called on an undone node if {@code isChanged() == b}. It is
   * the caller's responsibility to ensure that this does not happen. Calling {@code
   * markDirty(false)} when {@code isChanged() == true} has no effect. The idea here is that the
   * caller will only ever want to call {@code markDirty()} a second time if a transition from a
   * dirty-unchanged state to a dirty-changed state is required.
   *
   * @return A {@link ThinNodeEntry.MarkedDirtyResult} if the node was previously clean, and {@code
   *     null} if it was already dirty. If it was already dirty, the caller should abort its
   *     handling of this node, since another thread is already dealing with it. Note the warning on
   *     {@link ThinNodeEntry.MarkedDirtyResult} regarding the collection it provides.
   */
  @Nullable
  @ThreadSafe
  MarkedDirtyResult markDirty(boolean isChanged) throws InterruptedException;

  /**
   * Returned by {@link #markDirty} if that call changed the node from clean to dirty. Contains an
   * iterable of the node's reverse deps for efficiency, because the single use case for {@link
   * #markDirty} is during invalidation, and if such an invalidation call wins, the invalidator
   * must immediately afterwards schedule the invalidation of the node's reverse deps.
   *
   * <p>Warning: {@link #getReverseDepsUnsafe()} may return a live view of the reverse deps
   * collection of the marked-dirty node. The consumer of this data must be careful only to
   * iterate over and consume its values while that collection is guaranteed not to change. This
   * is true during invalidation, because reverse deps don't change during invalidation.
   */
  class MarkedDirtyResult {
    private final Iterable<SkyKey> reverseDepsUnsafe;

    public MarkedDirtyResult(Iterable<SkyKey> reverseDepsUnsafe) {
      this.reverseDepsUnsafe = Preconditions.checkNotNull(reverseDepsUnsafe);
    }

    public Iterable<SkyKey> getReverseDepsUnsafe() {
      return reverseDepsUnsafe;
    }
  }
}