[Bug 1066] New: Timer did not elapsed each time after re-arm

http://bugs.orocos.org/show_bug.cgi?id=1066

Summary: Timer did not elapsed each time after re-arm
Product: Toolchain
Version: unspecified
Platform: All
OS/Version: Xenomai 2.x
Status: NEW
Severity: enhancement
Priority: P3
Component: RTT
AssignedTo: orocos-dev [..] ...
ReportedBy: schwark [..] ...
CC: orocos-dev [..] ...
Estimated Hours: 0.0

If you arm a timer (RTT::Timer) after the timer elapsed, then sometimes the
timer will not elapsed again. In that case the timer is armed and the remaining
time is 0.

I've checked the RTT::Timer class (rtt/rtt/os/Timer.cpp) and maybe I found the
following mistake in Timer::loop():

The variable ret is not set correctly if wake_up_time is greater than
rtos_get_time_ns().
msem.waitUNtil returns a boolean value (0 or 1) and so ret is set to 0 or 1. If
I set ret to -1 or 1 then the problems seem to be solved.

original code:
...
if ( wake_up_time > rtos_get_time_ns() )
ret = msem.waitUntil( wake_up_time ); // case of no timers or running timers
else
ret = -1; // case of timer overrun.
...

changed code:
...
if ( wake_up_time > rtos_get_time_ns() )
{
if(!msem.waitUntil( wake_up_time )) // case of no timers or running timers
{
ret = -1;
}
}
else
{
ret = -1; // case of timer overrun.
}