adjust tls

This commit is contained in:
mutouyun 2019-01-20 20:31:55 +08:00
parent 52f447111c
commit a7d9a3d476
2 changed files with 5 additions and 4 deletions

View File

@ -63,7 +63,7 @@ public:
T* create(P&&... params) { T* create(P&&... params) {
auto ptr = static_cast<T*>(*this); auto ptr = static_cast<T*>(*this);
if (ptr == nullptr) { if (ptr == nullptr) {
return (*this) = new T { std::forward<P>(params)... }; return (*this) = new T(std::forward<P>(params)...);
} }
return ptr; return ptr;
} }

View File

@ -14,6 +14,7 @@
#include "def.h" #include "def.h"
#include "rw_lock.h" #include "rw_lock.h"
#include "tls_pointer.h"
namespace ipc { namespace ipc {
@ -42,7 +43,7 @@ public:
private: private:
rw_lock lc_; rw_lock lc_;
std::multimap<std::size_t, alloc_policy*, std::greater<std::size_t>> allocs_; std::multimap<std::size_t, alloc_policy*> allocs_;
struct alloc_t { struct alloc_t {
synchronized* t_; synchronized* t_;
@ -84,8 +85,8 @@ private:
}; };
auto& alc_info() { auto& alc_info() {
thread_local alloc_t alc { this }; static tls::pointer<alloc_t> alc;
return alc; return *alc.create(this);
} }
public: public: