[Bug 1057] New: RTT::os::Timer uses 100% cpu with no timers active on 32 bit linux

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

Summary: RTT::os::Timer uses 100% cpu with no timers active on
32 bit linux
Product: Toolchain
Version: master
Platform: All
OS/Version: GNU/Linux
Status: NEW
Severity: normal
Priority: P3
Component: RTT
AssignedTo: orocos-dev [..] ...
ReportedBy: dmytro [dot] poplavskiy [..] ...
CC: orocos-dev [..] ...
Estimated Hours: 0.0

When timer is started and killed on 32 bit linux,
RTT::os::Timer thread starts to use 100% CPU.

This is caused by requesting wait time too large to fit into 32 bit timespec.

Current Timer.cpp implementation:

// We can't use infinite as the OS may internally use time_spec, which can not
// represent as much in the future (until 2038) // XXX Year-2038 Bug
wake_up_time = (TimeService::InfiniteNSecs/4)-1;

While the comment is valid, the value used still does not fit the signed 32 bit
integer when converted to seconds,
so timespect value passed to sem_timedwait() has negative seconds time.

Changing this line to something like
wake_up_time = 1000000000LL * (2147483647-1); //
std::numeric_limits<int32_t>::max()-1 seconds in nanosecond

fixes the issue.

[Bug 1057] RTT::os::Timer uses 100% cpu with no timers active on