[Boost-bugs] [Boost C++ Libraries] #4533: timespec translation fails for times before 1970

Subject: [Boost-bugs] [Boost C++ Libraries] #4533: timespec translation fails for times before 1970
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-08-12 13:33:52


#4533: timespec translation fails for times before 1970
---------------------------------------------+------------------------------
 Reporter: Philipp Huber <phu@…> | Owner: anthonyw
     Type: Bugs | Status: new
Milestone: Boost 1.44.0 | Component: thread
  Version: Boost 1.43.0 | Severity: Problem
 Keywords: absolute time |
---------------------------------------------+------------------------------
 I had a target system that had always a failed assertion with a call to
 condition_variable::timed_wait();

 I found out, that pthread_cond_timedwait does not accept a timespec
 argument that has negative tv_nsec.

 Therefore I suggest the following patch, which works for me.

 ===================================================================
 --- /boost/boost_1_43_0/boost/thread/pthread/timespec.hpp (revision
 1769)
 +++ /boost/boost_1_43_0/boost/thread/pthread/timespec.hpp (working
 copy)
 @@ -26,6 +26,13 @@

              timeout.tv_sec=time_since_epoch.total_seconds();
 timeout.tv_nsec=(long)(time_since_epoch.fractional_seconds()*(1000000000l/time_since_epoch.ticks_per_second()));
 +
 + if(timeout.tv_nsec < 0L)
 + {
 + timeout.tv_sec -= 1L;
 + timeout.tv_nsec += 1000000000L;
 + }
 +
              return timeout;
          }
      }

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4533>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:04 UTC