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 `(<type>)`
but use C++ designed type casts like a static cast, for the
rest of operands in the formula.

Change-Id: Idbfff86f4ec805f3f6db144f3aa041f8fe2c017a
mr13.3.1
Donat Zenichev 2 years ago
parent cf281de9d4
commit 9c8ee14568

@ -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<float>(percent) / 100) * (static_cast<float>(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<float>(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<float>(cps_queue.size()) / cps_samplerate;
if (cps > max_cps) {
max_cps = cps;
}

@ -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<unsigned int, unsigned int> 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();
/**

Loading…
Cancel
Save