public long compareAddAndGet(long terminalState, long delta) {
    while (true) {
      long current = get();
      if (current == terminalState) {
        return terminalState;
      }
      long newValue = current + delta;
      if (compareAndSet(current, newValue)) {
        return newValue;
      }
    }
  }
Add and the the given delta to the long, unless the long has been set to the terminal state.

@return the new value of the field, or the terminalState if the field is already set to the
        terminal state.
geode-core/src/main/java/org/apache/geode/distributed/internal/AtomicLongWithTerminalState.java