This commit is contained in:
2019-02-19 22:35:27 +00:00
parent ae5dbd1e80
commit cc33879fd0
264 changed files with 214146 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
#include <unistd.h>
#include <sys/time.h>
#include "timer.h"
unsigned long stamp()
{
struct timeval tv;
gettimeofday( &tv, NULL );
return tv.tv_sec * 1000000 + tv.tv_usec;
}
CTimer::CTimer( )
{
prev = stamp();
}
void CTimer::init( )
{
prev = stamp();
}
void CTimer::wake( unsigned long usec )
{
long sleep_time = usec-(stamp()-prev);
if ( sleep_time>0 )
usleep( sleep_time );
prev = stamp();
}
bool CTimer::timeout( unsigned long usec )
{
return stamp()-prev > usec;
}
unsigned long CTimer::elapsed( )
{
return stamp()-prev;
}