cmTime.h/c : Added cmTimeDiffMicros(),cmTimeIsLTE(),cmTimeIsGTE(),cmTimeIsEqual(),cmTimeIsZero(),cmTimeSetZero().

This commit is contained in:
kevin 2013-12-17 08:55:08 -05:00
parent 07a49801dd
commit e11e660e52
2 changed files with 62 additions and 5 deletions

View File

@ -62,12 +62,52 @@ unsigned cmTimeElapsedMicros( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 )
unsigned cmTimeAbsElapsedMicros( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 ) unsigned cmTimeAbsElapsedMicros( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 )
{ {
if( t1->tv_sec > t0->tv_sec ) if( cmTimeIsLTE(t0,t1) )
return cmTimeElapsedMicros(t0,t1);
if( t1->tv_sec == t0->tv_sec )
if( t1->tv_nsec > t0->tv_nsec )
return cmTimeElapsedMicros(t0,t1); return cmTimeElapsedMicros(t0,t1);
return cmTimeElapsedMicros(t1,t0); return cmTimeElapsedMicros(t1,t0);
} }
int cmTimeDiffMicros( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 )
{
if( cmTimeIsLTE(t0,t1) )
return cmTimeElapsedMicros(t0,t1);
return -((int)cmTimeElapsedMicros(t1,t0));
}
bool cmTimeIsLTE( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 )
{
if( t0->tv_sec < t1->tv_sec )
return true;
if( t0->tv_sec == t1->tv_sec )
return t0->tv_nsec <= t1->tv_nsec;
return false;
}
bool cmTimeIsGTE( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 )
{
if( t0->tv_sec > t1->tv_sec )
return true;
if( t0->tv_sec == t1->tv_sec )
return t0->tv_nsec >= t1->tv_nsec;
return false;
}
bool cmTimeIsEqual( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 )
{ return t0->tv_sec==t1->tv_sec && t0->tv_nsec==t1->tv_nsec; }
bool cmTimeIsZero( const cmTimeSpec_t* t0 )
{ return t0->tv_sec==0 && t0->tv_nsec==0; }
void cmTimeSetZero( cmTimeSpec_t* t0 )
{
t0->tv_sec = 0;
t0->tv_nsec = 0;
}

View File

@ -33,6 +33,23 @@ extern "C" {
// The function therefore begins by swapping t1 and t0 if t0 is after t1. // The function therefore begins by swapping t1 and t0 if t0 is after t1.
unsigned cmTimeAbsElapsedMicros( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 ); unsigned cmTimeAbsElapsedMicros( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 );
// Same as cmTimeElapsedMicros() but returns a negative value if t0 is after t1.
int cmTimeDiffMicros( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 );
// Returns true if t0 <= t1.
bool cmTimeIsLTE( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 );
// Return true if t0 >= t1.
bool cmTimeIsGTE( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 );
bool cmTimeIsEqual( const cmTimeSpec_t* t0, const cmTimeSpec_t* t1 );
bool cmTimeIsZero( const cmTimeSpec_t* t0 );
void cmTimeSetZero( cmTimeSpec_t* t0 );
//) //)
//} //}