MT#62181 RegisterCache: add bindings set

Make AorEntry keep an ordered set of all bindings, ordered by expire
time. This makes it easy to quickly tell when the next binding is set to
expire, and which one. Store iterators to bindings in the set so that
they can be used to directly remove the binding when expired.

Change-Id: Ib63c15d5f6e8990e2f4d237726be54da76194a20
master
Richard Fuchs 1 month ago
parent f0fcaa7a7a
commit d00be5a396

@ -13,10 +13,12 @@
#include <map>
#include <unordered_map>
#include <memory>
#include <set>
using std::string;
using std::map;
using std::unordered_map;
using std::unique_ptr;
using std::set;
#define REG_CACHE_TABLE_POWER 10
#define REG_CACHE_TABLE_ENTRIES (1<<REG_CACHE_TABLE_POWER)
@ -54,14 +56,42 @@ public:
friend class AorEntry;
};
template<> struct std::less<unordered_map<string, RegBinding>::iterator>
{
bool operator()(const unordered_map<string, RegBinding>::iterator& a,
const unordered_map<string, RegBinding>::iterator& b) const
{
if (a->second.get_expire() < b->second.get_expire())
return true;
if (a->second.get_expire() > b->second.get_expire())
return false;
// for identical expire values we compare the pointer values of the original object
return &a->second < &b->second;
}
};
// Contact-URI/Public-IP -> RegBinding
class AorEntry : public unordered_map<string, RegBinding>
{
// members protected by AorEntry::lock
set<iterator> bindings_by_time;
void set_expire(const iterator& it, long int expire) {
if (it->second.reg_expire == expire)
return;
bindings_by_time.erase(it);
it->second.reg_expire = expire;
bindings_by_time.insert(it);
}
friend class AorHash;
public:
void erase(const iterator& it) {
bindings_by_time.erase(it);
unordered_map<string, RegBinding>::erase(it);
}
};
struct AliasEntry

Loading…
Cancel
Save