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