diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index 93321af..52d677e 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -2579,7 +2579,10 @@ class parallel_hash_set using key_arg = typename KeyArgImpl::template type; protected: - using Lockable = phmap::LockableImpl; + using Lockable = phmap::LockableImpl; + using UniqueLock = typename Lockable::UniqueLock; + using SharedLock = typename Lockable::SharedLock; + using ReadWriteLock = typename Lockable::ReadWriteLock; // -------------------------------------------------------------------- @@ -2631,9 +2634,7 @@ class parallel_hash_set // -------------------------------------------------------------------- template using RequiresInsertable = typename std::enable_if< - phmap::disjunction, - SameAsElementReference>::value, - int>::type; + phmap::disjunction, SameAsElementReference>::value, int>::type; // RequiresNotInit is a workaround for gcc prior to 7.1. // See https://godbolt.org/g/Y4xsUh. @@ -2960,7 +2961,7 @@ class parallel_hash_set PHMAP_ATTRIBUTE_REINITIALIZES void clear() { for (auto& inner : sets_) { - typename Lockable::UniqueLock m(inner); + UniqueLock m(inner); inner.set_.clear(); } } @@ -2969,7 +2970,7 @@ class parallel_hash_set // ---------------------------------------- void clear(std::size_t submap_index) { Inner& inner = sets_[submap_index]; - typename Lockable::UniqueLock m(inner); + UniqueLock m(inner); inner.set_.clear(); } @@ -3062,7 +3063,7 @@ class parallel_hash_set Inner& inner = sets_[subidx(hashval)]; auto& set = inner.set_; - typename Lockable::UniqueLock m(inner); + UniqueLock m(inner); auto res = set.insert(std::move(node), hashval); return { make_iterator(&inner, res.position), res.inserted, @@ -3125,7 +3126,7 @@ class parallel_hash_set const auto& elem = PolicyTraits::element(slot); Inner& inner = sets_[subidx(hashval)]; auto& set = inner.set_; - typename Lockable::UniqueLock m(inner); + UniqueLock m(inner); typename EmbeddedSet::template InsertSlotWithHash f { inner, std::move(*slot), hashval }; return make_rv(PolicyTraits::apply(f, elem)); } @@ -3144,7 +3145,7 @@ class parallel_hash_set { Inner& inner = sets_[subidx(hashval)]; auto& set = inner.set_; - typename Lockable::ReadWriteLock m(inner); + ReadWriteLock m(inner); size_t offset = set._find_key(key, hashval); if (offset == (size_t)-1 && m.switch_to_unique()) { @@ -3205,7 +3206,7 @@ class parallel_hash_set const auto& elem = PolicyTraits::element(slot); Inner& inner = sets_[subidx(hashval)]; auto& set = inner.set_; - typename Lockable::UniqueLock m(inner); + UniqueLock m(inner); typename EmbeddedSet::template InsertSlotWithHash f { inner, std::move(*slot), hashval }; return make_rv(PolicyTraits::apply(f, elem)); } @@ -3234,7 +3235,7 @@ class parallel_hash_set iterator lazy_emplace_with_hash(const key_arg& key, size_t hashval, F&& f) { Inner& inner = sets_[subidx(hashval)]; auto& set = inner.set_; - typename Lockable::ReadWriteLock m(inner); + ReadWriteLock m(inner); size_t offset = set._find_key(key, hashval); if (offset == (size_t)-1 && m.switch_to_unique()) { // we did an unlock/lock, and another thread could have inserted the same key, so we need to @@ -3260,7 +3261,7 @@ class parallel_hash_set void emplace_single_with_hash(const key_arg& key, size_t hashval, F&& f) { Inner& inner = sets_[subidx(hashval)]; auto& set = inner.set_; - typename Lockable::UniqueLock m(inner); + UniqueLock m(inner); set.emplace_single_with_hash(key, hashval, std::forward(f)); } @@ -3275,7 +3276,7 @@ class parallel_hash_set template bool if_contains(const key_arg& key, F&& f) const { return const_cast(this)->template - modify_if_impl(key, std::forward(f)); + modify_if_impl(key, std::forward(f)); } // if set contains key, lambda is called with the value_type without read lock protection, @@ -3293,7 +3294,7 @@ class parallel_hash_set // ---------------------------------------------------------------------------------------------------- template bool modify_if(const key_arg& key, F&& f) { - return modify_if_impl(key, std::forward(f)); + return modify_if_impl(key, std::forward(f)); } // ----------------------------------------------------------------------------------------- @@ -3317,7 +3318,7 @@ class parallel_hash_set // ---------------------------------------------------------------------------------------------------- template bool erase_if(const key_arg& key, F&& f) { - return erase_if_impl(key, std::forward(f)); + return erase_if_impl(key, std::forward(f)); } template @@ -3355,7 +3356,7 @@ class parallel_hash_set template bool lazy_emplace_l(const key_arg& key, FExists&& fExists, FEmplace&& fEmplace) { size_t hashval = this->hash(key); - typename Lockable::ReadWriteLock m; + ReadWriteLock m; auto res = this->find_or_prepare_insert_with_hash(hashval, key, m); Inner* inner = std::get<0>(res); if (std::get<2>(res)) { @@ -3380,7 +3381,7 @@ class parallel_hash_set template void for_each(F&& fCallback) const { for (auto const& inner : sets_) { - typename Lockable::SharedLock m(const_cast(inner)); + SharedLock m(const_cast(inner)); std::for_each(inner.set_.begin(), inner.set_.end(), fCallback); } } @@ -3389,7 +3390,7 @@ class parallel_hash_set template void for_each_m(F&& fCallback) { for (auto& inner : sets_) { - typename Lockable::UniqueLock m(inner); + UniqueLock m(inner); std::for_each(inner.set_.begin(), inner.set_.end(), fCallback); } } @@ -3400,7 +3401,7 @@ class parallel_hash_set std::for_each( std::forward(policy), sets_.begin(), sets_.end(), [&](auto const& inner) { - typename Lockable::SharedLock m(const_cast(inner)); + SharedLock m(const_cast(inner)); std::for_each(inner.set_.begin(), inner.set_.end(), fCallback); } ); @@ -3411,7 +3412,7 @@ class parallel_hash_set std::for_each( std::forward(policy), sets_.begin(), sets_.end(), [&](auto& inner) { - typename Lockable::UniqueLock m(inner); + UniqueLock m(inner); std::for_each(inner.set_.begin(), inner.set_.end(), fCallback); } ); @@ -3427,7 +3428,7 @@ class parallel_hash_set void with_submap(size_t idx, F&& fCallback) const { const Inner& inner = sets_[idx]; const auto& set = inner.set_; - typename Lockable::SharedLock m(const_cast(inner)); + SharedLock m(const_cast(inner)); fCallback(set); } @@ -3435,7 +3436,7 @@ class parallel_hash_set void with_submap_m(size_t idx, F&& fCallback) { Inner& inner = sets_[idx]; auto& set = inner.set_; - typename Lockable::UniqueLock m(inner); + UniqueLock m(inner); fCallback(set); } @@ -3492,7 +3493,7 @@ class parallel_hash_set Inner* inner = it.inner_; assert(inner != nullptr); auto& set = inner->set_; - // typename Lockable::UniqueLock m(*inner); // don't lock here + // UniqueLock m(*inner); // don't lock here set._erase(it.it_); } @@ -3566,7 +3567,7 @@ class parallel_hash_set size_t nn = n / num_tables; for (auto& inner : sets_) { - typename Lockable::UniqueLock m(inner); + UniqueLock m(inner); inner.set_.rehash(nn); } } @@ -3602,7 +3603,7 @@ class parallel_hash_set void prefetch_hash(size_t hashval) const { const Inner& inner = sets_[subidx(hashval)]; const auto& set = inner.set_; - typename Lockable::SharedLock m(const_cast(inner)); + SharedLock m(const_cast(inner)); set.prefetch_hash(hashval); } @@ -3621,7 +3622,7 @@ class parallel_hash_set // -------------------------------------------------------------------- template iterator find(const key_arg& key, size_t hashval) { - typename Lockable::SharedLock m; + SharedLock m; return find(key, hashval, m); } @@ -3669,7 +3670,7 @@ class parallel_hash_set size_t sz = 0; for (const auto& inner : sets_) { - typename Lockable::SharedLock m(const_cast(inner)); + SharedLock m(const_cast(inner)); sz += inner.set_.bucket_count(); } return sz; @@ -3765,7 +3766,7 @@ class parallel_hash_set void drop_deletes_without_resize() PHMAP_ATTRIBUTE_NOINLINE { for (auto& inner : sets_) { - typename Lockable::UniqueLock m(inner); + UniqueLock m(inner); inner.set_.drop_deletes_without_resize(); } } @@ -3774,7 +3775,7 @@ class parallel_hash_set size_t hashval = PolicyTraits::apply(HashElement{hash_ref()}, elem); Inner& inner = sets_[subidx(hashval)]; auto& set = inner.set_; - typename Lockable::SharedLock m(const_cast(inner)); + SharedLock m(const_cast(inner)); return set.has_element(elem, hashval); } @@ -3795,7 +3796,7 @@ class parallel_hash_set } protected: - template + template pointer find_ptr(const key_arg& key, size_t hashval, L& mutexlock) { Inner& inner = sets_[subidx(hashval)]; @@ -3804,7 +3805,7 @@ class parallel_hash_set return set.find_ptr(key, hashval); } - template + template iterator find(const key_arg& key, size_t hashval, L& mutexlock) { Inner& inner = sets_[subidx(hashval)]; auto& set = inner.set_; @@ -3814,10 +3815,10 @@ class parallel_hash_set template std::tuple - find_or_prepare_insert_with_hash(size_t hashval, const K& key, typename Lockable::ReadWriteLock &mutexlock) { + find_or_prepare_insert_with_hash(size_t hashval, const K& key, ReadWriteLock &mutexlock) { Inner& inner = sets_[subidx(hashval)]; auto& set = inner.set_; - mutexlock = std::move(typename Lockable::ReadWriteLock(inner)); + mutexlock = std::move(ReadWriteLock(inner)); size_t offset = set._find_key(key, hashval); if (offset == (size_t)-1 && mutexlock.switch_to_unique()) { // we did an unlock/lock, and another thread could have inserted the same key, so we need to @@ -3833,7 +3834,7 @@ class parallel_hash_set template std::tuple - find_or_prepare_insert(const K& key, typename Lockable::ReadWriteLock &mutexlock) { + find_or_prepare_insert(const K& key, ReadWriteLock &mutexlock) { return find_or_prepare_insert_with_hash(this->hash(key), key, mutexlock); } @@ -3901,7 +3902,10 @@ class parallel_hash_map : public parallel_hash_set::value && IsTransparent::value>; using Base = typename parallel_hash_map::parallel_hash_set; - using Lockable = phmap::LockableImpl; + using Lockable = phmap::LockableImpl; + using UniqueLock = typename Lockable::UniqueLock; + using SharedLock = typename Lockable::SharedLock; + using ReadWriteLock = typename Lockable::ReadWriteLock; public: using key_type = typename Policy::key_type; @@ -4052,7 +4056,7 @@ class parallel_hash_map : public parallel_hash_set bool try_emplace_l(K&& k, F&& f, Args&&... args) { size_t hashval = this->hash(k); - typename Lockable::ReadWriteLock m; + ReadWriteLock m; auto res = this->find_or_prepare_insert_with_hash(hashval, k, m); typename Base::Inner *inner = std::get<0>(res); if (std::get<2>(res)) { @@ -4073,7 +4077,7 @@ class parallel_hash_map : public parallel_hash_set std::pair try_emplace_p(K&& k, Args&&... args) { size_t hashval = this->hash(k); - typename Lockable::ReadWriteLock m; + ReadWriteLock m; auto res = this->find_or_prepare_insert_with_hash(hashval, k, m); typename Base::Inner *inner = std::get<0>(res); if (std::get<2>(res)) { @@ -4103,7 +4107,7 @@ class parallel_hash_map : public parallel_hash_set std::pair insert_or_assign_impl(K&& k, V&& v) { size_t hashval = this->hash(k); - typename Lockable::ReadWriteLock m; + ReadWriteLock m; auto res = this->find_or_prepare_insert_with_hash(hashval, k, m); typename Base::Inner *inner = std::get<0>(res); if (std::get<2>(res)) { @@ -4123,7 +4127,7 @@ class parallel_hash_map : public parallel_hash_set std::pair try_emplace_impl_with_hash(size_t hashval, K&& k, Args&&... args) { - typename Lockable::ReadWriteLock m; + ReadWriteLock m; auto res = this->find_or_prepare_insert_with_hash(hashval, k, m); typename Base::Inner *inner = std::get<0>(res); if (std::get<2>(res)) {