|
|
@ -4,6 +4,7 @@ |
|
|
|
#include <string> |
|
|
|
#include <string> |
|
|
|
#include <functional> |
|
|
|
#include <functional> |
|
|
|
#include <memory> |
|
|
|
#include <memory> |
|
|
|
|
|
|
|
#include <mutex> |
|
|
|
#include <boost/asio.hpp> |
|
|
|
#include <boost/asio.hpp> |
|
|
|
|
|
|
|
|
|
|
|
#ifdef ANDROID |
|
|
|
#ifdef ANDROID |
|
|
@ -71,11 +72,44 @@ namespace util |
|
|
|
std::bind (&MemoryPool<T>::Release, this, std::placeholders::_1)); |
|
|
|
std::bind (&MemoryPool<T>::Release, this, std::placeholders::_1)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
protected: |
|
|
|
|
|
|
|
|
|
|
|
T * m_Head; |
|
|
|
T * m_Head; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T> |
|
|
|
|
|
|
|
class MemoryPoolMt: public MemoryPool<T> |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MemoryPoolMt () {}; |
|
|
|
|
|
|
|
template<typename... TArgs> |
|
|
|
|
|
|
|
T * AcquireMt (TArgs&&... args) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!this->m_Head) return new T(args...); |
|
|
|
|
|
|
|
std::lock_guard<std::mutex> l(m_Mutex); |
|
|
|
|
|
|
|
return this->Acquire (args...); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ReleaseMt (T * t) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::lock_guard<std::mutex> l(m_Mutex); |
|
|
|
|
|
|
|
this->Release (t); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<template<typename, typename...>class C, typename... R> |
|
|
|
|
|
|
|
void ReleaseMt(const C<T *, R...>& c) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::lock_guard<std::mutex> l(m_Mutex); |
|
|
|
|
|
|
|
for (auto& it: c) |
|
|
|
|
|
|
|
this->Release (it); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::mutex m_Mutex; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
namespace net |
|
|
|
namespace net |
|
|
|
{ |
|
|
|
{ |
|
|
|
int GetMTU (const boost::asio::ip::address& localAddress); |
|
|
|
int GetMTU (const boost::asio::ip::address& localAddress); |
|
|
|