mirror of
https://github.com/ShaYmez/P25Clients.git
synced 2025-07-06 03:05:20 -04:00
Update the StopWatch.
This commit is contained in:
parent
248b0840d4
commit
a322bb7345
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016,2018 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -52,6 +52,7 @@ unsigned int CStopWatch::elapsed()
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
CStopWatch::CStopWatch() :
|
CStopWatch::CStopWatch() :
|
||||||
m_start()
|
m_start()
|
||||||
@ -64,21 +65,19 @@ CStopWatch::~CStopWatch()
|
|||||||
|
|
||||||
unsigned long CStopWatch::start()
|
unsigned long CStopWatch::start()
|
||||||
{
|
{
|
||||||
::gettimeofday(&m_start, NULL);
|
::clock_gettime(CLOCK_MONOTONIC, &m_start);
|
||||||
|
|
||||||
return m_start.tv_usec;
|
return m_start.tv_sec * 1000UL + m_start.tv_nsec / 1000000UL;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CStopWatch::elapsed()
|
unsigned int CStopWatch::elapsed()
|
||||||
{
|
{
|
||||||
struct timeval now;
|
struct timespec now;
|
||||||
::gettimeofday(&now, NULL);
|
::clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
|
||||||
unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U;
|
int offset = ((now.tv_sec - m_start.tv_sec) * 1000000000UL + now.tv_nsec - m_start.tv_nsec ) / 1000000UL;
|
||||||
elapsed += now.tv_usec / 1000U;
|
|
||||||
elapsed -= m_start.tv_usec / 1000U;
|
|
||||||
|
|
||||||
return elapsed;
|
return (unsigned int)offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016,2018 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -39,7 +39,7 @@ private:
|
|||||||
LARGE_INTEGER m_frequency;
|
LARGE_INTEGER m_frequency;
|
||||||
LARGE_INTEGER m_start;
|
LARGE_INTEGER m_start;
|
||||||
#else
|
#else
|
||||||
struct timeval m_start;
|
struct timespec m_start;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016,2018 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -52,6 +52,7 @@ unsigned int CStopWatch::elapsed()
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
CStopWatch::CStopWatch() :
|
CStopWatch::CStopWatch() :
|
||||||
m_start()
|
m_start()
|
||||||
@ -64,21 +65,19 @@ CStopWatch::~CStopWatch()
|
|||||||
|
|
||||||
unsigned long CStopWatch::start()
|
unsigned long CStopWatch::start()
|
||||||
{
|
{
|
||||||
::gettimeofday(&m_start, NULL);
|
::clock_gettime(CLOCK_MONOTONIC, &m_start);
|
||||||
|
|
||||||
return m_start.tv_usec;
|
return m_start.tv_sec * 1000UL + m_start.tv_nsec / 1000000UL;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CStopWatch::elapsed()
|
unsigned int CStopWatch::elapsed()
|
||||||
{
|
{
|
||||||
struct timeval now;
|
struct timespec now;
|
||||||
::gettimeofday(&now, NULL);
|
::clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
|
||||||
unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U;
|
int offset = ((now.tv_sec - m_start.tv_sec) * 1000000000UL + now.tv_nsec - m_start.tv_nsec ) / 1000000UL;
|
||||||
elapsed += now.tv_usec / 1000U;
|
|
||||||
elapsed -= m_start.tv_usec / 1000U;
|
|
||||||
|
|
||||||
return elapsed;
|
return (unsigned int)offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016,2018 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -39,7 +39,7 @@ private:
|
|||||||
LARGE_INTEGER m_frequency;
|
LARGE_INTEGER m_frequency;
|
||||||
LARGE_INTEGER m_start;
|
LARGE_INTEGER m_start;
|
||||||
#else
|
#else
|
||||||
struct timeval m_start;
|
struct timespec m_start;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016,2018 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -52,6 +52,7 @@ unsigned int CStopWatch::elapsed()
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
CStopWatch::CStopWatch() :
|
CStopWatch::CStopWatch() :
|
||||||
m_start()
|
m_start()
|
||||||
@ -64,21 +65,19 @@ CStopWatch::~CStopWatch()
|
|||||||
|
|
||||||
unsigned long CStopWatch::start()
|
unsigned long CStopWatch::start()
|
||||||
{
|
{
|
||||||
::gettimeofday(&m_start, NULL);
|
::clock_gettime(CLOCK_MONOTONIC, &m_start);
|
||||||
|
|
||||||
return m_start.tv_usec;
|
return m_start.tv_sec * 1000UL + m_start.tv_nsec / 1000000UL;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CStopWatch::elapsed()
|
unsigned int CStopWatch::elapsed()
|
||||||
{
|
{
|
||||||
struct timeval now;
|
struct timespec now;
|
||||||
::gettimeofday(&now, NULL);
|
::clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
|
||||||
unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U;
|
int offset = ((now.tv_sec - m_start.tv_sec) * 1000000000UL + now.tv_nsec - m_start.tv_nsec ) / 1000000UL;
|
||||||
elapsed += now.tv_usec / 1000U;
|
|
||||||
elapsed -= m_start.tv_usec / 1000U;
|
|
||||||
|
|
||||||
return elapsed;
|
return (unsigned int)offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016,2018 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -39,7 +39,7 @@ private:
|
|||||||
LARGE_INTEGER m_frequency;
|
LARGE_INTEGER m_frequency;
|
||||||
LARGE_INTEGER m_start;
|
LARGE_INTEGER m_start;
|
||||||
#else
|
#else
|
||||||
struct timeval m_start;
|
struct timespec m_start;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user