Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.concurrent;
00018
00019
00023 public class WallTimeRate implements Rate {
00024
00025 private final long delay;
00026
00027 private long time;
00028
00029 public WallTimeRate(int hz) {
00030 delay = 1000 / hz;
00031 time = 0;
00032 }
00033
00034 @Override
00035 public void sleep() {
00036 long delta = System.currentTimeMillis() - time;
00037 while (delta < delay) {
00038 try {
00039 Thread.sleep(delay - delta);
00040 } catch (InterruptedException e) {
00041 break;
00042 }
00043 delta = System.currentTimeMillis() - time;
00044 }
00045 time = System.currentTimeMillis();
00046 }
00047 }