MT#62181 replace atomic_int class

Use std::atomic_int instead.

Change-Id: I2bc1af5591bdfa880c700f9820a3c8b87784b3eb
mr13.3.1
Richard Fuchs 2 years ago
parent bdb3f2c295
commit 5f332dff40

@ -418,7 +418,7 @@ void _RegisterCache::update(const string& alias, long int reg_expires,
uri.c_str(), alias.c_str());
// inc stats
active_regs.inc();
active_regs++;
ContactBucket* ct_bucket = getContactBucket(uri,alias_update.source_ip,
alias_update.source_port);
@ -540,7 +540,7 @@ void _RegisterCache::update(long int reg_expires, const AliasEntry& alias_update
compute_alias_hash(canon_aor,uri,public_ip);
// inc stats
active_regs.inc();
active_regs++;
string idx = uri + "/" + public_ip;
aor_e->insert(AorEntry::value_type(idx, binding));
@ -721,7 +721,7 @@ void _RegisterCache::removeAlias(const string& alias, bool generate_event)
ct_bucket->unlock();
// dec stats
active_regs.dec();
active_regs--;
storage_handler->onDelete(ae->aor,
ae->contact_uri,

@ -354,7 +354,7 @@ public:
/**
* Statistics
*/
unsigned int getActiveRegs() { return active_regs.get(); }
unsigned int getActiveRegs() { return active_regs; }
};
typedef singleton<_RegisterCache> RegisterCache;

@ -1382,7 +1382,7 @@ void SBCCallLeg::onAfterRTPRelay(AmRtpPacket* p, sockaddr_storage* remote_addr)
{
for(list<atomic_int*>::iterator it = rtp_pegs.begin();
it != rtp_pegs.end(); ++it) {
(*it)->inc(p->getBufferSize());
(*it) += (p->getBufferSize());
}
}

@ -1,192 +1,13 @@
#ifndef _atomic_types_h_
#define _atomic_types_h_
#if (__GNUC__ > 4) || \
(__GNUC__ == 4 && __GNUC_MINOR__ >= 1) && \
( \
(defined(__APPLE__) && \
( \
defined(__ppc__) || \
defined(__i386__) || \
defined(__x86_64__) \
) \
) || \
(defined(__linux__) && \
( \
(defined(__i386__) && (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4))) || \
defined(__ia64__) || \
defined(__x86_64__) || \
(defined(__powerpc__) && !defined(__powerpc64__)) || \
defined(__alpha) \
) \
) \
)
#define HAVE_ATOMIC_CAS 1
#else
// #warning Compare and Swap is not supported on this architecture
#define HAVE_ATOMIC_CAS 0
#endif
#include <assert.h>
#include "log.h"
#if !HAVE_ATOMIC_CAS
#include "AmThread.h"
#endif
// 32 bit unsigned integer
class atomic_int
#if !HAVE_ATOMIC_CAS
: protected AmMutex
#endif
{
volatile unsigned int i;
public:
atomic_int() : i(0) {}
void set(unsigned int val) {
i = val;
}
unsigned int get() const {
return i;
}
#if HAVE_ATOMIC_CAS
// ++i;
unsigned int inc(unsigned int add=1) {
return __sync_add_and_fetch(&i,add);
}
// --i;
unsigned int dec(unsigned int sub=1) {
return __sync_sub_and_fetch(&i,sub);
}
#else // if HAVE_ATOMIC_CAS
// ++i;
unsigned int inc(unsigned int add=1) {
unsigned int res;
lock();
res = (i += add);
unlock();
return res;
}
#include <atomic>
// --i;
unsigned int dec(unsigned int sub=1) {
unsigned int res;
lock();
res = (i -= sub);
unlock();
return res;
}
#endif
// return --ll != 0;
bool dec_and_test() {
return dec() == 0;
};
};
using std::atomic_int;
// 64 bit unsigned integer
class atomic_int64
#if !HAVE_ATOMIC_CAS
: protected AmMutex
#endif
{
volatile unsigned long long ll;
public:
atomic_int64(): ll(0) {}
#if HAVE_ATOMIC_CAS
void set(unsigned long long val) {
#if !defined(__LP64__) || !__LP64__
unsigned long long tmp_ll;
do {
tmp_ll = ll;
}
while(!__sync_bool_compare_and_swap(&ll, tmp_ll, val));
#else
ll = val;
#endif
}
unsigned long long get() {
#if !defined(__LP64__) || !__LP64__
unsigned long long tmp_ll;
do {
tmp_ll = ll;
}
while(!__sync_bool_compare_and_swap(&ll, tmp_ll, tmp_ll));
return tmp_ll;
#else
return ll;
#endif
}
// returns ++ll;
unsigned long long inc(unsigned long long add=1) {
return __sync_add_and_fetch(&ll,add);
}
// returns --ll;
unsigned long long dec(unsigned long long sub=1) {
return __sync_sub_and_fetch(&ll,sub);
}
#else // if HAVE_ATOMIC_CAS
void set(unsigned long long val) {
#if !defined(__LP64__) || !__LP64__
lock();
ll = val;
unlock();
#else
ll = val;
#endif
}
unsigned long long get() {
#if !defined(__LP64__) || !__LP64__
unsigned long long tmp_ll;
lock();
tmp_ll = ll;
unlock();
return tmp_ll;
#else
return ll;
#endif
}
// returns ++ll;
unsigned long long inc(unsigned long long add=1) {
unsigned long long res;
lock();
res = (ll += add);
unlock();
return res;
}
// returns --ll;
unsigned long long dec(unsigned long long sub=1) {
unsigned long long res;
lock();
res = (ll -= sub);
unlock();
return res;
}
#endif
// return --ll == 0;
bool dec_and_test() {
return dec() == 0;
};
};
class atomic_ref_cnt;
void inc_ref(atomic_ref_cnt* rc);
@ -199,8 +20,8 @@ class atomic_ref_cnt
protected:
atomic_ref_cnt() {}
void _inc_ref() { ref_cnt.inc(); }
bool _dec_ref() { return ref_cnt.dec_and_test(); }
void _inc_ref() { ++ref_cnt; }
bool _dec_ref() { return --ref_cnt == 0; }
virtual ~atomic_ref_cnt() {}
virtual void on_destroy() {}

@ -86,30 +86,30 @@ class trans_stats
public:
/** increment number of sent requests */
void inc_sent_requests() { sent_requests.inc(); }
void inc_sent_requests() { sent_requests++; }
/** increment number of sent replies */
void inc_sent_replies() { sent_replies.inc(); }
void inc_sent_replies() { sent_replies++; }
/** increment number of received requests */
void inc_received_requests() { received_requests.inc(); }
void inc_received_requests() { received_requests++; }
/** increment number of received replies */
void inc_received_replies() { received_replies.inc(); }
void inc_received_replies() { received_replies++; }
/** increment number of sent request retransmissions */
void inc_sent_request_retrans() { sent_request_retrans.inc(); }
void inc_sent_request_retrans() { sent_request_retrans++; }
/** increment number of sent reply retransmissions */
void inc_sent_reply_retrans() { sent_reply_retrans.inc(); }
void inc_sent_reply_retrans() { sent_reply_retrans++; }
unsigned get_sent_requests() const { return sent_requests.get(); }
unsigned get_sent_replies() const { return sent_replies.get(); }
unsigned get_received_requests() const { return received_requests.get(); }
unsigned get_received_replies() const { return received_replies.get(); }
unsigned get_sent_request_retrans() const { return sent_request_retrans.get(); }
unsigned get_sent_reply_retrans() const { return sent_reply_retrans.get(); }
unsigned get_sent_requests() const { return sent_requests; }
unsigned get_sent_replies() const { return sent_replies; }
unsigned get_received_requests() const { return received_requests; }
unsigned get_received_replies() const { return received_replies; }
unsigned get_sent_request_retrans() const { return sent_request_retrans; }
unsigned get_sent_reply_retrans() const { return sent_reply_retrans; }
};
/**

@ -513,8 +513,8 @@ static atomic_int __branch_cnt;
void compute_sl_to_tag(char* to_tag/*[8]*/, const sip_msg* msg)
{
unsigned int hl = __branch_cnt.inc();
unsigned int hh = __branch_cnt.inc();
unsigned int hl = ++__branch_cnt;
unsigned int hh = ++__branch_cnt;
assert(msg->type == SIP_REQUEST);
assert(msg->u.request);
@ -549,8 +549,8 @@ void compute_branch(char* branch/*[8]*/, const cstring& callid, const cstring& c
unsigned int hh=0;
timeval tv;
hh = __branch_cnt.inc();
hl = __branch_cnt.inc();
hh = ++__branch_cnt;
hl = ++__branch_cnt;
hl = hashlittle(callid.s,callid.len,hl);
hh = hashlittle(cseq.s,cseq.len,hh);

Loading…
Cancel
Save