Files
redAcore/TimingCore.cpp
Charl Wentzel 8fd04dc9e2 Important Update:
- CItemBuffer:
  - Rename CItemBufferCore -> CItemBuffer
  - Add item count and GetCount() method
  - Bug fix: Reset LastItem on DeleteAll()
- TimingCore:
  - Bug fix: Handle buffer overflow on 32-bit processors
2017-08-17 10:56:10 +02:00

69 lines
1.7 KiB
C++

/*
* TimingCore.cpp
*
* Created on: 13 May 2016
* Author: wentzelc
*/
// Standard C/C++ Libraries
#include <time.h>
#include <limits.h>
// redA Libraries
#include "TimingCore.h"
//---------------------------------------------------------------------------
// Set time
void SetInterval( timeval * Time, long MilliSeconds )
{
// milli-seconds -> seconds
Time->tv_sec = MilliSeconds / 1000;
// milli-seconds -> micro-seconds
Time->tv_usec = (MilliSeconds % 1000) * 1000;
}
//---------------------------------------------------------------------------
// Populated start time
void SetStartTime( timeval * StartTime )
{
// Get current time
gettimeofday( StartTime, NULL );
}
//---------------------------------------------------------------------------
// Clear start time
void ClearStartTime( timeval * StartTime )
{
// Get current time
StartTime->tv_sec = 0;
StartTime->tv_usec = 0;
}
//---------------------------------------------------------------------------
// Calculate TimePassed from Start Time (in milli-seconds)
long TimePassed( timeval StartTime )
{
timeval CurrTime;
long Duration;
// Get current time
gettimeofday( &CurrTime, NULL );
// Get time passed in milli-seconds
Duration = (CurrTime.tv_sec - StartTime.tv_sec) * (time_t)1000 +
(CurrTime.tv_usec - StartTime.tv_usec) / (time_t)1000;
if (Duration < 0)
Duration = LONG_MAX;
return Duration;
}
//---------------------------------------------------------------------------
bool Timeout( timeval StartTime, long MilliSeconds )
{
return ((TimePassed(StartTime) > MilliSeconds)? true : false);
}
//---------------------------------------------------------------------------