[openrtm-commit:00995] r686 - trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext
openrtm @ openrtm.org
openrtm @ openrtm.org
2013年 2月 11日 (月) 01:15:59 JST
Author: ga
Date: 2013-02-11 01:15:59 +0900 (Mon, 11 Feb 2013)
New Revision: 686
Modified:
trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java
trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java
Log:
The bugs about Thread.sleep() have been fixed.
Modified: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java 2013-02-06 04:57:23 UTC (rev 685)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java 2013-02-10 16:15:59 UTC (rev 686)
@@ -168,10 +168,22 @@
}
try {
period = period.minus(t1_d);
- Thread.sleep((int)(period.toDouble() * 1000),(int)(period.toDouble() * 1000000000));
+ int millisec = 0;
+ int nanosec = (int)(period.toDouble()*1000000000);
+ if ( nanosec > 999999) {
+ millisec = nanosec / 1000000;
+ nanosec = nanosec % 1000000;
+ }
+
+ if ( millisec > 0 || nanosec > 0) {
+ Thread.sleep(millisec,nanosec);
+ }
} catch (InterruptedException e){
e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
}
+
}
} while (threadRunning());
@@ -579,8 +591,21 @@
}
try
{
- Thread.sleep((int)(getPeriod().toDouble()*1000),(int)(getPeriod().toDouble()*1000000000));
- }catch(InterruptedException e){}
+ int millisec = 0;
+ int nanosec = (int)(getPeriod().toDouble()*1000000000);
+ if ( nanosec > 999999) {
+ millisec = nanosec / 1000000;
+ nanosec = nanosec % 1000000;
+ }
+
+ if ( millisec > 0 || nanosec > 0) {
+ Thread.sleep(millisec,nanosec);
+ }
+ } catch (InterruptedException e){
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
TimeValue delta= new TimeValue();
delta.convert(System.nanoTime()/1000000000.0);
delta = delta.minus(starttime);
@@ -675,8 +700,21 @@
}
try
{
- Thread.sleep((int)(getPeriod().toDouble()*1000),(int)(getPeriod().toDouble()*1000000000));
- }catch(InterruptedException e){}
+ int millisec = 0;
+ int nanosec = (int)(getPeriod().toDouble()*1000000000);
+ if ( nanosec > 999999) {
+ millisec = nanosec / 1000000;
+ nanosec = nanosec % 1000000;
+ }
+
+ if ( millisec > 0 || nanosec > 0) {
+ Thread.sleep(millisec,nanosec);
+ }
+ } catch (InterruptedException e){
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
TimeValue delta = new TimeValue();
delta.convert(System.nanoTime()/1000000000.0);
delta = delta.minus(starttime);
@@ -770,8 +808,21 @@
}
try
{
- Thread.sleep((int)(getPeriod().toDouble()*1000),(int)(getPeriod().toDouble()*1000000000));
- }catch(InterruptedException e){}
+ int millisec = 0;
+ int nanosec = (int)(getPeriod().toDouble()*1000000000);
+ if ( nanosec > 999999) {
+ millisec = nanosec / 1000000;
+ nanosec = nanosec % 1000000;
+ }
+
+ if ( millisec > 0 || nanosec > 0) {
+ Thread.sleep(millisec,nanosec);
+ }
+ } catch (InterruptedException e){
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
TimeValue delta = new TimeValue();
delta.convert(System.nanoTime()/1000000000.0);
delta = delta.minus(starttime);
Modified: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java 2013-02-06 04:57:23 UTC (rev 685)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java 2013-02-10 16:15:59 UTC (rev 686)
@@ -176,10 +176,22 @@
}
try {
delta = period.minus(delta);
- Thread.sleep((int)(delta.toDouble()*1000),(int)(delta.toDouble()*1000000000)); // sec -> millisec, sec -> nanosec
+ int millisec = 0;
+ int nanosec = (int)(delta.toDouble()*1000000000);
+ if ( nanosec > 999999) {
+ millisec = nanosec / 1000000;
+ nanosec = nanosec % 1000000;
+ }
+
+ if ( millisec > 0 || nanosec > 0) {
+ Thread.sleep(millisec,nanosec);
+ }
} catch (InterruptedException e){
e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
}
+
}
++count;
@@ -639,8 +651,22 @@
}
try
{
- Thread.sleep((int)(getPeriod().toDouble()*1000),(int)(getPeriod().toDouble()*1000000000)); // sec -> millisec, sec -> nanosec
- }catch(InterruptedException e){}
+ int millisec = 0;
+ int nanosec = (int)(getPeriod().toDouble()*1000000000);
+ if ( nanosec > 999999) {
+ millisec = nanosec / 1000000;
+ nanosec = nanosec % 1000000;
+ }
+
+ if ( millisec > 0 || nanosec > 0) {
+ Thread.sleep(millisec,nanosec);
+ }
+ } catch(InterruptedException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
TimeValue delta= new TimeValue();
delta.convert(System.nanoTime()/1000000000);
delta = delta.minus(starttime);
@@ -734,8 +760,21 @@
}
try
{
- Thread.sleep((int)(getPeriod().toDouble()*1000),(int)(getPeriod().toDouble()*1000000000)); // sec -> millisec, sec -> nanosec
- }catch(InterruptedException e){}
+ int millisec = 0;
+ int nanosec = (int)(getPeriod().toDouble()*1000000000);
+ if ( nanosec > 999999) {
+ millisec = nanosec / 1000000;
+ nanosec = nanosec % 1000000;
+ }
+
+ if ( millisec > 0 || nanosec > 0) {
+ Thread.sleep(millisec, nanosec);
+ }
+ } catch(InterruptedException e){
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
TimeValue delta = new TimeValue();
delta.convert(System.nanoTime()/1000);
delta = delta.minus(starttime);
@@ -829,8 +868,21 @@
}
try
{
- Thread.sleep((int)(getPeriod().toDouble()*1000),(int)(getPeriod().toDouble()*1000000000)); // sec -> millisec, sec -> nanosec
- }catch(InterruptedException e){}
+ int millisec = 0;
+ int nanosec = (int)(getPeriod().toDouble()*1000000000);
+ if ( nanosec > 999999) {
+ millisec = nanosec / 1000000;
+ nanosec = nanosec % 1000000;
+ }
+
+ if ( millisec > 0 || nanosec > 0) {
+ Thread.sleep(millisec, nanosec);
+ }
+ } catch(InterruptedException e){
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
TimeValue delta = new TimeValue();
delta.convert(System.nanoTime()/1000);
delta = delta.minus(starttime);
More information about the openrtm-commit
mailing list