Implemented NamedCounter method that allows adding a specific value to the counter.

git-svn-id: http://yate.null.ro/svn/yate/trunk@6541 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
oana 2022-02-03 15:49:57 +00:00
parent 10bdfb1bfe
commit 169a579ea8
2 changed files with 21 additions and 0 deletions

View File

@ -1436,6 +1436,21 @@ int NamedCounter::dec()
#endif
}
int NamedCounter::add(int val)
{
#ifdef ATOMIC_OPS
#ifdef _WINDOWS
return InterlockedExchangeAdd((LONG*)&m_count,(LONG)val);
#else
return __sync_add_and_fetch(&m_count,val);
#endif
#else
Lock lock(m_mutex);
m_count += val;
return m_count;
#endif
}
void SysUsage::init()
{

View File

@ -3656,6 +3656,12 @@ public:
*/
int dec();
/**
* Add a specific value to the counter
* @param val Value to add
*/
int add(int val);
/**
* Get the current value of the counter
* @return Value of the counter