Commit 73b6ea42 authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

(timers): used steady_clock instead high_resolution_clock

parent 4ed50544
...@@ -314,7 +314,7 @@ void UNetReceiver::statisticsEvent(ev::periodic& tm, int revents) noexcept ...@@ -314,7 +314,7 @@ void UNetReceiver::statisticsEvent(ev::periodic& tm, int revents) noexcept
return; return;
} }
t_end = chrono::high_resolution_clock::now(); t_end = chrono::steady_clock::now();
float sec = chrono::duration_cast<chrono::duration<float>>(t_end - t_stats).count(); float sec = chrono::duration_cast<chrono::duration<float>>(t_end - t_stats).count();
t_stats = t_end; t_stats = t_end;
stats.recvPerSec = recvCount / sec; stats.recvPerSec = recvCount / sec;
...@@ -537,7 +537,7 @@ void UNetReceiver::readEvent( ev::io& watcher ) noexcept ...@@ -537,7 +537,7 @@ void UNetReceiver::readEvent( ev::io& watcher ) noexcept
return; return;
bool ok = false; bool ok = false;
t_start = chrono::high_resolution_clock::now(); t_start = chrono::steady_clock::now();
try try
{ {
...@@ -564,7 +564,7 @@ void UNetReceiver::readEvent( ev::io& watcher ) noexcept ...@@ -564,7 +564,7 @@ void UNetReceiver::readEvent( ev::io& watcher ) noexcept
ptRecvTimeout.reset(); ptRecvTimeout.reset();
} }
t_end = chrono::high_resolution_clock::now(); t_end = chrono::steady_clock::now();
stats.recvProcessingTime_microsec = std::chrono::duration_cast<std::chrono::microseconds>(t_end - t_start).count(); stats.recvProcessingTime_microsec = std::chrono::duration_cast<std::chrono::microseconds>(t_end - t_start).count();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -621,7 +621,7 @@ void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept ...@@ -621,7 +621,7 @@ void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept
bool recvOk = checkConnection(); bool recvOk = checkConnection();
// обновление данных в SM // обновление данных в SM
t_start = chrono::high_resolution_clock::now(); t_start = chrono::steady_clock::now();
try try
{ {
...@@ -632,7 +632,7 @@ void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept ...@@ -632,7 +632,7 @@ void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept
unetcrit << myname << "(updateEvent): " << ex.what() << std::endl; unetcrit << myname << "(updateEvent): " << ex.what() << std::endl;
} }
t_end = chrono::high_resolution_clock::now(); t_end = chrono::steady_clock::now();
stats.upProcessingTime_microsec = std::chrono::duration_cast<std::chrono::microseconds>(t_end - t_start).count(); stats.upProcessingTime_microsec = std::chrono::duration_cast<std::chrono::microseconds>(t_end - t_start).count();
if( sidRespond != DefaultObjectId ) if( sidRespond != DefaultObjectId )
......
...@@ -218,9 +218,9 @@ namespace uniset ...@@ -218,9 +218,9 @@ namespace uniset
// счётчики для подсчёта статистики // счётчики для подсчёта статистики
size_t recvCount = { 0 }; size_t recvCount = { 0 };
size_t upCount = { 0 }; size_t upCount = { 0 };
std::chrono::system_clock::time_point t_start; std::chrono::steady_clock::time_point t_start;
std::chrono::system_clock::time_point t_end; std::chrono::steady_clock::time_point t_end;
std::chrono::system_clock::time_point t_stats; std::chrono::steady_clock::time_point t_stats;
// текущая статистика // текущая статистика
struct Stats struct Stats
......
...@@ -277,7 +277,7 @@ int main(int argc, char* argv[]) ...@@ -277,7 +277,7 @@ int main(int argc, char* argv[])
if( ncycles > 0 ) if( ncycles > 0 )
nc = ncycles; nc = ncycles;
auto t_start = high_resolution_clock::now(); auto t_start = steady_clock::now();
unsigned int npack = 0; unsigned int npack = 0;
...@@ -287,7 +287,7 @@ int main(int argc, char* argv[]) ...@@ -287,7 +287,7 @@ int main(int argc, char* argv[])
{ {
if( nprof > 0 && npack >= nprof ) if( nprof > 0 && npack >= nprof )
{ {
auto t_end = high_resolution_clock::now(); auto t_end = steady_clock::now();
float sec = duration_cast<duration<float>>(t_end - t_start).count(); float sec = duration_cast<duration<float>>(t_end - t_start).count();
cout << "Receive " << setw(5) << npack << " packets for " << setw(8) << sec << " sec " cout << "Receive " << setw(5) << npack << " packets for " << setw(8) << sec << " sec "
<< " [ 1 packet per " << setw(10) << ( sec / (float)npack ) << " sec ]" << endl; << " [ 1 packet per " << setw(10) << ( sec / (float)npack ) << " sec ]" << endl;
......
...@@ -229,7 +229,7 @@ int main(int argc, char* argv[]) ...@@ -229,7 +229,7 @@ int main(int argc, char* argv[])
if( ncycles > 0 ) if( ncycles > 0 )
nc = ncycles; nc = ncycles;
auto t_start = high_resolution_clock::now(); auto t_start = steady_clock::now();
unsigned int npack = 0; unsigned int npack = 0;
...@@ -239,7 +239,7 @@ int main(int argc, char* argv[]) ...@@ -239,7 +239,7 @@ int main(int argc, char* argv[])
{ {
if( nprof > 0 && npack >= nprof ) if( nprof > 0 && npack >= nprof )
{ {
auto t_end = high_resolution_clock::now(); auto t_end = steady_clock::now();
float sec = duration_cast<duration<float>>(t_end - t_start).count(); float sec = duration_cast<duration<float>>(t_end - t_start).count();
cout << "Receive " << setw(5) << npack << " packets for " << setw(8) << sec << " sec " cout << "Receive " << setw(5) << npack << " packets for " << setw(8) << sec << " sec "
<< " [ 1 packet per " << setw(10) << ( sec / (float)npack ) << " sec ]" << endl; << " [ 1 packet per " << setw(10) << ( sec / (float)npack ) << " sec ]" << endl;
......
...@@ -118,7 +118,7 @@ namespace uniset ...@@ -118,7 +118,7 @@ namespace uniset
// отделяем внутреннее (теперь уже стандартное >= c++11) // отделяем внутреннее (теперь уже стандартное >= c++11)
// представление для работы со временем (std::chrono) // представление для работы со временем (std::chrono)
// и тип (t_msec) для "пользователей" // и тип (t_msec) для "пользователей"
std::chrono::high_resolution_clock::time_point t_start; /*!< время установки таймера (сброса) */ std::chrono::steady_clock::time_point t_start; /*!< время установки таймера (сброса) */
std::chrono::milliseconds t_inner_msec; /*!< время установки таймера, мсек (в единицах std::chrono) */ std::chrono::milliseconds t_inner_msec; /*!< время установки таймера, мсек (в единицах std::chrono) */
private: private:
......
...@@ -63,7 +63,7 @@ namespace uniset ...@@ -63,7 +63,7 @@ namespace uniset
do do
{ {
status = future.wait_for(std::chrono::milliseconds(tout_msec)); status = future.wait_until(std::chrono::steady_clock::now() + std::chrono::milliseconds(tout_msec));
if( status == std::future_status::timeout ) if( status == std::future_status::timeout )
return false; return false;
...@@ -99,7 +99,7 @@ namespace uniset ...@@ -99,7 +99,7 @@ namespace uniset
do do
{ {
status = future.wait_for(std::chrono::milliseconds(tout_msec)); status = future.wait_until(std::chrono::steady_clock::now() + std::chrono::milliseconds(tout_msec));
if( status == std::future_status::timeout ) if( status == std::future_status::timeout )
return false; return false;
......
...@@ -297,7 +297,7 @@ namespace uniset ...@@ -297,7 +297,7 @@ namespace uniset
ulogsys << "(FINISH GUARD THREAD): wait " << TERMINATE_TIMEOUT_SEC << " sec.." << endl << flush; ulogsys << "(FINISH GUARD THREAD): wait " << TERMINATE_TIMEOUT_SEC << " sec.." << endl << flush;
g_doneevent.wait_for(lk, std::chrono::milliseconds(TERMINATE_TIMEOUT_SEC * 1000), []() g_doneevent.wait_until(lk, std::chrono::steady_clock::now() + std::chrono::milliseconds(TERMINATE_TIMEOUT_SEC * 1000), []()
{ {
return (g_done == true); return (g_done == true);
} ); } );
......
...@@ -46,7 +46,7 @@ namespace uniset ...@@ -46,7 +46,7 @@ namespace uniset
thr = unisetstd::make_unique<std::thread>( [&] { CommonEventLoop::defaultLoop(); } ); thr = unisetstd::make_unique<std::thread>( [&] { CommonEventLoop::defaultLoop(); } );
std::unique_lock<std::mutex> lock2(looprunOK_mutex); std::unique_lock<std::mutex> lock2(looprunOK_mutex);
looprunOK_event.wait_for(lock2, std::chrono::milliseconds(waitTimeout_msec), [&]() looprunOK_event.wait_until(lock2, std::chrono::steady_clock::now() + std::chrono::milliseconds(waitTimeout_msec), [&]()
{ {
return (isrunning == true); return (isrunning == true);
} ); } );
...@@ -70,7 +70,7 @@ namespace uniset ...@@ -70,7 +70,7 @@ namespace uniset
evprep.send(); // будим default loop evprep.send(); // будим default loop
// ожидаем обработки evprepare (которая будет в defaultLoop) // ожидаем обработки evprepare (которая будет в defaultLoop)
prep_event.wait_for(locker, std::chrono::milliseconds(waitTimeout_msec), [ = ]() prep_event.wait_until(locker, std::chrono::steady_clock::now() + std::chrono::milliseconds(waitTimeout_msec), [ = ]()
{ {
return ( prep_notify == true ); return ( prep_notify == true );
} ); } );
......
...@@ -171,7 +171,7 @@ namespace uniset ...@@ -171,7 +171,7 @@ namespace uniset
return true; return true;
std::unique_lock<std::mutex> lock(looprunOK_mutex); std::unique_lock<std::mutex> lock(looprunOK_mutex);
looprunOK_event.wait_for(lock, std::chrono::milliseconds(waitTimeout_msec), [&]() looprunOK_event.wait_until(lock, std::chrono::steady_clock::now() + std::chrono::milliseconds(waitTimeout_msec), [&]()
{ {
return (isrunning == true); return (isrunning == true);
} ); } );
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <sstream> #include <sstream>
#include <time.h> #include <time.h>
#include "PassiveTimer.h" #include "PassiveTimer.h"
#include <iostream>
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
using namespace std; using namespace std;
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
...@@ -66,10 +67,12 @@ namespace uniset ...@@ -66,10 +67,12 @@ namespace uniset
cv_working.wait(lk); cv_working.wait(lk);
} }
else else
cv_working.wait_for(lk, std::chrono::milliseconds(t_msec), [&]() {
cv_working.wait_until(lk, std::chrono::steady_clock::now() + std::chrono::milliseconds(t_msec), [&]()
{ {
return (terminated == true); return (terminated == true);
} ); });
}
terminated = true; terminated = true;
return true; return true;
......
...@@ -51,7 +51,7 @@ namespace uniset ...@@ -51,7 +51,7 @@ namespace uniset
if( t_msec == 0 ) if( t_msec == 0 )
return true; return true;
return ( std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - t_start).count() >= t_inner_msec.count() ); return ( std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - t_start).count() >= t_inner_msec.count() );
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -72,13 +72,13 @@ namespace uniset ...@@ -72,13 +72,13 @@ namespace uniset
// Запустить таймер // Запустить таймер
void PassiveTimer::reset(void) noexcept void PassiveTimer::reset(void) noexcept
{ {
t_start = std::chrono::high_resolution_clock::now(); t_start = std::chrono::steady_clock::now();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// получить текущее значение таймера // получить текущее значение таймера
timeout_t PassiveTimer::getCurrent() const noexcept timeout_t PassiveTimer::getCurrent() const noexcept
{ {
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - t_start).count(); return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - t_start).count();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
timeout_t PassiveTimer::getInterval() const noexcept timeout_t PassiveTimer::getInterval() const noexcept
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment