while (lock.test_and_set(std::memory_order_acquire)) // acquire lock ; // spin
template<typename Key, typename Value, typename Args...>void insert(Key key, Args args...){ struct Deleter { Key key; Hash *hash; // тут weak_ptr возможно? Deleter(Key key, Hash *hash) : key(std::move(key)), hash(hash) {} void operator(Value *) { const auto it = hash->find(key); if (it != hash->end()) erase(it); delete ptr; } }; Deleter deleter(key, this); m_map.insert({std::reference_wrapper(deleter.key), std::make_shared<Value, deleter>(std::forward(args...)});}
template<typename Key, typename Value, typename Args...>void insert(Key key, Args args...){ auto &data = m_map[key]; const auto &keyRef = data.first; // нам гарантируют стабильность ссылок auto deleter = [this, keyRef](Value *) { if (const auto it = m_map.find(keyRef); it != m_map.end()) erase(it); delete ptr; }; data.second = std::shared_ptr<Value, ???>(new Value(std::forward(args...)), deleter);}
if (!strong.deref()) deleteValue();if (!weak.deref()) deleteControlBlock();
if (!strong.deref()) <--- point A deleteValue();if (!weak.deref()) deleteControlBlock();