From 9c8ee145688999c6ebeb0c67cb81b79aa81a4a73 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Sat, 15 Feb 2025 20:51:23 +0100 Subject: [PATCH] MT#61878 trixie: eliminate implicit operations: enum vs float C++20 deprecates implicit conversion of enumerations during math operations like division. Instead deprecate enum CPS_SAMPLERATE which is used in a role of pre-proc definition and add a `const float` value of which is defined by the constructor and is unchangable. Also don't use straight-forward (old style) cast with `()` but use C++ designed type casts like a static cast, for the rest of operands in the formula. Change-Id: Idbfff86f4ec805f3f6db144f3aa041f8fe2c017a --- core/AmSessionContainer.cpp | 14 +++++++------- core/AmSessionContainer.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/AmSessionContainer.cpp b/core/AmSessionContainer.cpp index f18c9651..1f5248e1 100644 --- a/core/AmSessionContainer.cpp +++ b/core/AmSessionContainer.cpp @@ -45,7 +45,7 @@ _MONITORING_DECLARE_INTERFACE(AmSessionContainer); AmSessionContainer::AmSessionContainer() : _run_cond(false), _container_closed(false), enable_unclean_shutdown(false), - CPSLimit(0), CPSHardLimit(0), max_cps(0) + CPSLimit(0), CPSHardLimit(0), max_cps(0), cps_samplerate(5) { } @@ -399,14 +399,14 @@ void AmSessionContainer::setCPSSoftLimit(unsigned int percent) while (cps_queue.size()) { timersub(&tv, &cps_queue.front(), &res); - if (res.tv_sec >= CPS_SAMPLERATE) { + if (res.tv_sec >= cps_samplerate) { cps_queue.pop(); } else { break; } } - CPSLimit = ((float)percent / 100) * ((float)cps_queue.size() / CPS_SAMPLERATE); + CPSLimit = (static_cast(percent) / 100) * (static_cast(cps_queue.size()) / cps_samplerate); if(0 == CPSLimit) CPSLimit = 1; } @@ -425,7 +425,7 @@ unsigned int AmSessionContainer::getAvgCPS() while (cps_queue.size()) { timersub(&tv, &cps_queue.front(), &res); - if (res.tv_sec >= CPS_SAMPLERATE) { + if (res.tv_sec >= cps_samplerate) { cps_queue.pop(); } else { @@ -433,7 +433,7 @@ unsigned int AmSessionContainer::getAvgCPS() } } - return (float)cps_queue.size() / CPS_SAMPLERATE; + return static_cast(cps_queue.size()) / cps_samplerate; } unsigned int AmSessionContainer::getMaxCPS() @@ -465,7 +465,7 @@ bool AmSessionContainer::check_and_add_cps(bool emergency_flag) while (cps_queue.size()) { timersub(&tv, &cps_queue.front(), &res); - if (res.tv_sec >= CPS_SAMPLERATE) { + if (res.tv_sec >= cps_samplerate) { cps_queue.pop(); } else { @@ -473,7 +473,7 @@ bool AmSessionContainer::check_and_add_cps(bool emergency_flag) } } - unsigned int cps = (float)cps_queue.size() / CPS_SAMPLERATE; + unsigned int cps = static_cast(cps_queue.size()) / cps_samplerate; if (cps > max_cps) { max_cps = cps; } diff --git a/core/AmSessionContainer.h b/core/AmSessionContainer.h index 514c14cf..c6b73769 100644 --- a/core/AmSessionContainer.h +++ b/core/AmSessionContainer.h @@ -93,7 +93,7 @@ class AmSessionContainer : public AmThread /** Mutex to protect the cps container */ AmMutex cps_mut; - enum { CPS_SAMPLERATE = 5 }; + const float cps_samplerate; unsigned int CPSLimit; unsigned int CPSHardLimit; @@ -197,7 +197,7 @@ class AmSessionContainer : public AmThread pair getCPSLimit(); /** - * Gets the timeaverage of calls per second in the last CPS_SAMPLERATE sec window + * Gets the timeaverage of calls per second in the last cps_samplerate sec window */ unsigned int getAvgCPS(); /**