Skip to content

Commit

Permalink
HSEARCH-4069 Avoid to init timing source if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever authored and yrodiere committed Nov 5, 2020
1 parent ab48be8 commit d8b66fb
Showing 1 changed file with 14 additions and 5 deletions.
Expand Up @@ -73,20 +73,25 @@ public TimeoutManager(TimingSource timingSource, Long timeoutValue, TimeUnit tim
this.type = type;
this.deadline = timeoutMs == null ? null : new DynamicDeadline();

timingSource.ensureTimeEstimateIsInitialized();
if ( requireMonotonicTimeEstimate() ) {
timingSource.ensureTimeEstimateIsInitialized();
}
}

/**
* we start counting from this method call (if needed)
*/
public void start() {
this.monotonicTimeEstimateStart = timingSource.monotonicTimeEstimate();
this.nanoTimeStart = timingSource.nanoTime();
if ( requireMonotonicTimeEstimate() ) {
monotonicTimeEstimateStart = timingSource.monotonicTimeEstimate();
}

nanoTimeStart = timingSource.nanoTime();
}

public void stop() {
this.monotonicTimeEstimateStart = null;
this.nanoTimeStart = null;
monotonicTimeEstimateStart = null;
nanoTimeStart = null;
}

public TimingSource timingSource() {
Expand Down Expand Up @@ -155,6 +160,10 @@ protected long elapsedTimeEstimateMillis() {
return timingSource.monotonicTimeEstimate() - monotonicTimeEstimateStart;
}

private boolean requireMonotonicTimeEstimate() {
return !Type.NONE.equals( type );
}

final class DynamicDeadline implements Deadline {
boolean timedOut = false;

Expand Down

0 comments on commit d8b66fb

Please sign in to comment.