cwTime.h/cpp : Added advanceMicros().

This commit is contained in:
kevin 2023-01-14 17:15:55 -05:00
parent 4039613124
commit 748bf9ab44
2 changed files with 26 additions and 1 deletions

View File

@ -212,6 +212,30 @@ void cw::time::subtractMicros( spec_t& ts, unsigned micros )
}
void cw::time::advanceMicros( spec_t& ts, unsigned us )
{
if( us > 1000000 )
{
// strip off whole seconds from usec
unsigned sec = us / 1000000;
// find the remaining fractional second in microseconds
us = (us - sec*1000000);
ts.tv_sec += sec;
}
ts.tv_nsec += us * 1000000000; // convert microseconds to nanoseconds
// stip off whole seconds from tv_nsec
while( ts.tv_nsec > 1e9 )
{
ts.tv_nsec -= 1e9;
ts.tv_sec +=1;
}
}
void cw::time::advanceMs( spec_t& ts, unsigned ms )
{
if( ms > 1000 )

View File

@ -65,7 +65,8 @@ namespace cw
void subtractMicros( spec_t& ts, unsigned us );
// Advance 'ts' by 'ms' milliseconds.
// Advance 'ts' by 'us/'ms' microseconds/milliseconds.
void advanceMicros( spec_t& ts, unsigned us );
void advanceMs( spec_t& ts, unsigned ms );
// Advance the current time by 'ms' milliseconds;