cwTime.h/cpp : Added advanceMicros().
This commit is contained in:
parent
4039613124
commit
748bf9ab44
24
cwTime.cpp
24
cwTime.cpp
@ -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 )
|
void cw::time::advanceMs( spec_t& ts, unsigned ms )
|
||||||
{
|
{
|
||||||
if( ms > 1000 )
|
if( ms > 1000 )
|
||||||
|
3
cwTime.h
3
cwTime.h
@ -65,7 +65,8 @@ namespace cw
|
|||||||
|
|
||||||
void subtractMicros( spec_t& ts, unsigned us );
|
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 );
|
void advanceMs( spec_t& ts, unsigned ms );
|
||||||
|
|
||||||
// Advance the current time by 'ms' milliseconds;
|
// Advance the current time by 'ms' milliseconds;
|
||||||
|
Loading…
Reference in New Issue
Block a user