mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-30 04:37:50 +02:00
use memory pool for tunnel messages
This commit is contained in:
parent
4ce7e192d6
commit
ae0cf2e831
4 changed files with 56 additions and 16 deletions
|
@ -56,12 +56,8 @@ namespace util
|
|||
|
||||
void CleanUp ()
|
||||
{
|
||||
while (m_Head)
|
||||
{
|
||||
auto tmp = m_Head;
|
||||
m_Head = static_cast<T*>(*(void * *)m_Head); // next
|
||||
::operator delete ((void *)tmp);
|
||||
}
|
||||
CleanUp (m_Head);
|
||||
m_Head = nullptr;
|
||||
}
|
||||
|
||||
template<typename... TArgs>
|
||||
|
@ -98,6 +94,18 @@ namespace util
|
|||
std::bind (&MemoryPool<T>::Release, this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void CleanUp (T * head)
|
||||
{
|
||||
while (head)
|
||||
{
|
||||
auto tmp = head;
|
||||
head = static_cast<T*>(*(void * *)head); // next
|
||||
::operator delete ((void *)tmp);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
T * m_Head;
|
||||
|
@ -131,6 +139,24 @@ namespace util
|
|||
this->Release (it);
|
||||
}
|
||||
|
||||
template<typename... TArgs>
|
||||
std::shared_ptr<T> AcquireSharedMt (TArgs&&... args)
|
||||
{
|
||||
return std::shared_ptr<T>(AcquireMt (std::forward<TArgs>(args)...),
|
||||
std::bind<void (MemoryPoolMt<T>::*)(T *)> (&MemoryPoolMt<T>::ReleaseMt, this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void CleanUpMt ()
|
||||
{
|
||||
T * head;
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_Mutex);
|
||||
head = this->m_Head;
|
||||
this->m_Head = nullptr;
|
||||
}
|
||||
if (head) this->CleanUp (head);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::mutex m_Mutex;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue