Improved time handling by using helper function
This commit is contained in:
parent
e0351ca367
commit
00a617150e
|
@ -336,7 +336,7 @@ genCPPCSPTime ops e
|
|||
tell ["unsigned ",curTimeLow," = (unsigned)remainder(1000000.0 * ",curTime,",4294967296.0);"]
|
||||
tell ["unsigned ",curTimeHigh," = (unsigned)((1000000.0 * ",curTime,") / 4294967296.0);"]
|
||||
--if time is less than curTime, it must have wrapped around so add one:
|
||||
tell ["csp::Time ",retTime," = csp::Seconds((((double)(",curTimeHigh," + (",time," < ",curTimeLow, " ? 1 : 0)) * 4294967296.0) + (double)",time,") / 1000000.0);"]
|
||||
tell ["csp::Time ",retTime," = csp::Seconds((((double)(",curTimeHigh," + TimeDiffHelper(",curTimeLow,",",time,")) * 4294967296.0) + (double)",time,") / 1000000.0);"]
|
||||
return retTime
|
||||
|
||||
cppgenTimerWait :: GenOps -> A.Expression -> CGen ()
|
||||
|
|
|
@ -35,6 +35,35 @@ public:
|
|||
#include <boost/preprocessor/repetition/repeat.hpp>
|
||||
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
||||
|
||||
inline unsigned TimeDiffHelper(unsigned now,unsigned waitFor)
|
||||
{
|
||||
//If waitFor is in the 2^31 before now, it is in the past:
|
||||
if (now - waitFor < 2147483648)
|
||||
{
|
||||
//if we have wrapped round between waitFor and now, we actually want to return a minus-one:
|
||||
if ((waitFor >= 2147483648) && (now < 2147483648))
|
||||
{
|
||||
return (unsigned)(int)(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//It is in the future. If we will wrap round before getting there, return one:
|
||||
if ((now >= 2147483648) && (waitFor < 2147483648))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class StreamWriter : public csp::CSProcess
|
||||
{
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue
Block a user