From a322bb734528a387b9904e70045d6816559da227 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Wed, 4 Jul 2018 21:48:08 +0100 Subject: [PATCH] Update the StopWatch. --- P25Gateway/StopWatch.cpp | 17 ++++++++--------- P25Gateway/StopWatch.h | 4 ++-- P25Parrot/StopWatch.cpp | 17 ++++++++--------- P25Parrot/StopWatch.h | 4 ++-- P25Reflector/StopWatch.cpp | 17 ++++++++--------- P25Reflector/StopWatch.h | 4 ++-- 6 files changed, 30 insertions(+), 33 deletions(-) diff --git a/P25Gateway/StopWatch.cpp b/P25Gateway/StopWatch.cpp index 77d539d..eb32961 100644 --- a/P25Gateway/StopWatch.cpp +++ b/P25Gateway/StopWatch.cpp @@ -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 * it under the terms of the GNU General Public License as published by @@ -52,6 +52,7 @@ unsigned int CStopWatch::elapsed() #else #include +#include CStopWatch::CStopWatch() : m_start() @@ -64,21 +65,19 @@ CStopWatch::~CStopWatch() 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() { - struct timeval now; - ::gettimeofday(&now, NULL); + struct timespec now; + ::clock_gettime(CLOCK_MONOTONIC, &now); - unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U; - elapsed += now.tv_usec / 1000U; - elapsed -= m_start.tv_usec / 1000U; + int offset = ((now.tv_sec - m_start.tv_sec) * 1000000000UL + now.tv_nsec - m_start.tv_nsec ) / 1000000UL; - return elapsed; + return (unsigned int)offset; } #endif diff --git a/P25Gateway/StopWatch.h b/P25Gateway/StopWatch.h index 811047e..554f91c 100644 --- a/P25Gateway/StopWatch.h +++ b/P25Gateway/StopWatch.h @@ -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 * 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_start; #else - struct timeval m_start; + struct timespec m_start; #endif }; diff --git a/P25Parrot/StopWatch.cpp b/P25Parrot/StopWatch.cpp index 77d539d..eb32961 100644 --- a/P25Parrot/StopWatch.cpp +++ b/P25Parrot/StopWatch.cpp @@ -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 * it under the terms of the GNU General Public License as published by @@ -52,6 +52,7 @@ unsigned int CStopWatch::elapsed() #else #include +#include CStopWatch::CStopWatch() : m_start() @@ -64,21 +65,19 @@ CStopWatch::~CStopWatch() 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() { - struct timeval now; - ::gettimeofday(&now, NULL); + struct timespec now; + ::clock_gettime(CLOCK_MONOTONIC, &now); - unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U; - elapsed += now.tv_usec / 1000U; - elapsed -= m_start.tv_usec / 1000U; + int offset = ((now.tv_sec - m_start.tv_sec) * 1000000000UL + now.tv_nsec - m_start.tv_nsec ) / 1000000UL; - return elapsed; + return (unsigned int)offset; } #endif diff --git a/P25Parrot/StopWatch.h b/P25Parrot/StopWatch.h index 811047e..554f91c 100644 --- a/P25Parrot/StopWatch.h +++ b/P25Parrot/StopWatch.h @@ -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 * 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_start; #else - struct timeval m_start; + struct timespec m_start; #endif }; diff --git a/P25Reflector/StopWatch.cpp b/P25Reflector/StopWatch.cpp index 77d539d..eb32961 100644 --- a/P25Reflector/StopWatch.cpp +++ b/P25Reflector/StopWatch.cpp @@ -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 * it under the terms of the GNU General Public License as published by @@ -52,6 +52,7 @@ unsigned int CStopWatch::elapsed() #else #include +#include CStopWatch::CStopWatch() : m_start() @@ -64,21 +65,19 @@ CStopWatch::~CStopWatch() 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() { - struct timeval now; - ::gettimeofday(&now, NULL); + struct timespec now; + ::clock_gettime(CLOCK_MONOTONIC, &now); - unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U; - elapsed += now.tv_usec / 1000U; - elapsed -= m_start.tv_usec / 1000U; + int offset = ((now.tv_sec - m_start.tv_sec) * 1000000000UL + now.tv_nsec - m_start.tv_nsec ) / 1000000UL; - return elapsed; + return (unsigned int)offset; } #endif diff --git a/P25Reflector/StopWatch.h b/P25Reflector/StopWatch.h index 811047e..554f91c 100644 --- a/P25Reflector/StopWatch.h +++ b/P25Reflector/StopWatch.h @@ -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 * 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_start; #else - struct timeval m_start; + struct timespec m_start; #endif };