public static MonotonicTime getCurrentTime() { MonotonicTime monotonicTime = new MonotonicTime(); monotonicTime.setToCurrentTime(); return monotonicTime; }
public MonotonicTime(long seconds, long nanoseconds) { this.seconds = seconds; this.nanoseconds = nanoseconds; normalize(); }
@Override public void run() { while(true) { controller.read(RealtimeThread.getCurrentMonotonicClockTime()); controller.run(); long currentTime = RealtimeThread.getCurrentMonotonicClockTime(); controller.write(currentTime); // Checks if there is a non-zero sleep duration. If not, sleep for 0.1ms. This avoids busy waits and preempting kernel tasks. if(controller.nextWakeupTime() != Long.MIN_VALUE && controller.nextWakeupTime() >= currentTime) { triggerTime.set(0, controller.nextWakeupTime()); } else { triggerTime.setToCurrentTime(); triggerTime.add(defaultTriggerTime); } waitUntil(triggerTime); } } }
public long waitUntil(MonotonicTime time) { return RealtimeNative.waitUntil(threadID, time.seconds(), time.nanoseconds()); }
@Override public void getNextTriggerTime(MonotonicTime timeToPack) { long timestamp = RealtimeNative.getNextPeriod(threadID); timeToPack.set(0, timestamp); }
public PeriodicParameters(long periodInNanoSeconds) { this.startTime = null; this.period = new MonotonicTime(0, periodInNanoSeconds); }
public long waitUntil(MonotonicTime time) { return RealtimeNative.waitUntil(threadID, time.seconds(), time.nanoseconds()); }
@Override public void getNextTriggerTime(MonotonicTime timeToPack) { long timestamp = RealtimeNative.getNextPeriod(threadID); timeToPack.set(0, timestamp); }
public PeriodicParameters(long periodInNanoSeconds) { this.startTime = null; this.period = new MonotonicTime(0, periodInNanoSeconds); }
public void setNextPeriod(MonotonicTime nextControllerTrigger) { RealtimeNative.setNextPeriod(threadID, nextControllerTrigger.seconds(), nextControllerTrigger.nanoseconds()); }
public void subNanoseconds(long nanoseconds) { this.nanoseconds -= nanoseconds; normalize(); }
public static MonotonicTime getCurrentTime() { MonotonicTime monotonicTime = new MonotonicTime(); monotonicTime.setToCurrentTime(); return monotonicTime; }
@Override public void run() { while(true) { controller.read(RealtimeThread.getCurrentMonotonicClockTime()); controller.run(); controller.write(RealtimeThread.getCurrentMonotonicClockTime()); if(controller.nextWakeupTime() != Long.MIN_VALUE) { triggerTime.set(0, controller.nextWakeupTime()); waitUntil(triggerTime); } } }
@Override public void schedule(Runnable runnable, long period, TimeUnit timeunit) { if(thread != null) { throw new RuntimeException("Thread has already been scheduled"); } MonotonicTime time = new MonotonicTime(0, TimeUnit.NANOSECONDS.convert(period, timeunit)); PeriodicParameters periodicParameters = new PeriodicParameters(time); thread = new PeriodicRealtimeThread(priorityParameters, periodicParameters, runnable, name); thread.start(); }
public void setNextPeriod(MonotonicTime nextControllerTrigger) { RealtimeNative.setNextPeriod(threadID, nextControllerTrigger.seconds(), nextControllerTrigger.nanoseconds()); }
public MonotonicTime(long seconds, long nanoseconds) { this.seconds = seconds; this.nanoseconds = nanoseconds; normalize(); }
@Override public void schedule(Runnable runnable, long period, TimeUnit timeunit) { if(thread != null) { throw new RuntimeException("Thread has already been scheduled"); } MonotonicTime time = new MonotonicTime(0, TimeUnit.NANOSECONDS.convert(period, timeunit)); PeriodicParameters periodicParameters = new PeriodicParameters(time); thread = new PeriodicRealtimeThread(priorityParameters, periodicParameters, runnable, name); thread.start(); }
startSeconds = periodicParameters.getStartTime().seconds(); startNanos = periodicParameters.getStartTime().nanoseconds(); periodSeconds = periodicParameters.getPeriod().seconds(); periodNanos = periodicParameters.getPeriod().nanoseconds();
public void set(long seconds, long nanoseconds) { this.seconds = seconds; this.nanoseconds = nanoseconds; normalize(); }
PeriodicParameters periodicParameters = new PeriodicParameters(new MonotonicTime(0, periodInNS));