memory pool for address vectors

This commit is contained in:
orignal 2022-12-07 14:08:27 -05:00
parent 8ad5696e50
commit 53ca5dc67a
4 changed files with 19 additions and 12 deletions

View File

@ -649,7 +649,8 @@ namespace data
} // m_RouterInfos iteration
m_RouterInfoBuffersPool.CleanUpMt ();
// m_RouterInfoAddressesPool.CleanUpMt ();
m_RouterInfoAddressesPool.CleanUpMt ();
m_RouterInfoAddressVectorsPool.CleanUpMt ();
if (updatedCount > 0)
LogPrint (eLogInfo, "NetDb: Saved ", updatedCount, " new/updated routers");

View File

@ -123,7 +123,14 @@ namespace data
void ClearRouterInfos () { m_RouterInfos.clear (); };
std::shared_ptr<RouterInfo::Buffer> NewRouterInfoBuffer () { return m_RouterInfoBuffersPool.AcquireSharedMt (); };
void PopulateRouterInfoBuffer (std::shared_ptr<RouterInfo> r);
//std::shared_ptr<RouterInfo::Address> NewRouterInfoAddress () { return m_RouterInfoAddressesPool.AcquireSharedMt (); };
std::shared_ptr<RouterInfo::Address> NewRouterInfoAddress () { return m_RouterInfoAddressesPool.AcquireSharedMt (); };
boost::shared_ptr<RouterInfo::Addresses> NewRouterInfoAddresses ()
{
return boost::shared_ptr<RouterInfo::Addresses>(m_RouterInfoAddressVectorsPool.AcquireMt (),
std::bind <void (i2p::util::MemoryPoolMt<RouterInfo::Addresses>::*)(RouterInfo::Addresses *)>
(&i2p::util::MemoryPoolMt<RouterInfo::Addresses>::ReleaseMt,
&m_RouterInfoAddressVectorsPool, std::placeholders::_1));
};
std::shared_ptr<Lease> NewLease (const Lease& lease) { return m_LeasesPool.AcquireSharedMt (lease); };
uint32_t GetPublishReplyToken () const { return m_PublishReplyToken; };
@ -181,7 +188,8 @@ namespace data
uint32_t m_PublishReplyToken = 0;
i2p::util::MemoryPoolMt<RouterInfo::Buffer> m_RouterInfoBuffersPool;
//i2p::util::MemoryPoolMt<RouterInfo::Address> m_RouterInfoAddressesPool;
i2p::util::MemoryPoolMt<RouterInfo::Address> m_RouterInfoAddressesPool;
i2p::util::MemoryPoolMt<RouterInfo::Addresses> m_RouterInfoAddressVectorsPool;
i2p::util::MemoryPoolMt<Lease> m_LeasesPool;
};

View File

@ -206,13 +206,14 @@ namespace data
s.read ((char *)&m_Timestamp, sizeof (m_Timestamp));
m_Timestamp = be64toh (m_Timestamp);
// read addresses
if (!m_NewAddresses) m_NewAddresses = boost::make_shared<Addresses>();
auto addresses = netdb.NewRouterInfoAddresses ();
uint8_t numAddresses;
s.read ((char *)&numAddresses, sizeof (numAddresses));
addresses->reserve (numAddresses);
for (int i = 0; i < numAddresses; i++)
{
uint8_t supportedTransports = 0;
auto address = std::make_shared<Address> (); // netdb.NewRouterInfoAddress ();
auto address = netdb.NewRouterInfoAddress ();
uint8_t cost; // ignore
s.read ((char *)&cost, sizeof (cost));
s.read ((char *)&address->date, sizeof (address->date));
@ -417,19 +418,16 @@ namespace data
if (supportedTransports)
{
if (!(m_SupportedTransports & supportedTransports)) // avoid duplicates
m_NewAddresses->push_back(address);
addresses->push_back(address);
m_SupportedTransports |= supportedTransports;
}
}
// update addresses
auto prev = m_Addresses;
#if (BOOST_VERSION >= 105300)
boost::atomic_store (&m_Addresses, m_NewAddresses);
boost::atomic_store (&m_Addresses, addresses);
#else
m_Addresses = m_NewAddresses; // race condition
m_Addresses = addresses; // race condition
#endif
if (prev) prev->clear ();
m_NewAddresses = prev;
// read peers
uint8_t numPeers;
s.read ((char *)&numPeers, sizeof (numPeers)); if (!s) return;

View File

@ -281,7 +281,7 @@ namespace data
std::shared_ptr<Buffer> m_Buffer;
size_t m_BufferLen;
uint64_t m_Timestamp;
boost::shared_ptr<Addresses> m_Addresses, m_NewAddresses; // TODO: use std::shared_ptr and std::atomic_store for gcc >= 4.9
boost::shared_ptr<Addresses> m_Addresses; // TODO: use std::shared_ptr and std::atomic_store for gcc >= 4.9
bool m_IsUpdated, m_IsUnreachable;
CompatibleTransports m_SupportedTransports, m_ReachableTransports;
uint8_t m_Caps;