@@ -3721,14 +3721,9 @@ class parallel_hash_set {
37213721 std::pair<iterator, bool > emplace_decomposable_with_hash (const K& key, size_t hashval, Args&&... args) {
37223722 Inner& inner = sets_[subidx (hashval)];
37233723 auto & set = inner.set_ ;
3724- ReadWriteLock m (inner);
3724+ UniqueLock m (inner);
37253725
37263726 size_t offset = set._find_key (key, hashval);
3727- if (offset == (size_t )-1 && m.switch_to_unique ()) {
3728- // we did an unlock/lock, and another thread could have inserted the same key, so we need to
3729- // do a find() again.
3730- offset = set._find_key (key, hashval);
3731- }
37323727 if (offset == (size_t )-1 ) {
37333728 offset = set.prepare_insert (hashval);
37343729 set.emplace_at (offset, std::forward<Args>(args)...);
@@ -3807,13 +3802,8 @@ class parallel_hash_set {
38073802 iterator lazy_emplace_with_hash (const key_arg<K>& key, size_t hashval, F&& f) {
38083803 Inner& inner = sets_[subidx (hashval)];
38093804 auto & set = inner.set_ ;
3810- ReadWriteLock m (inner);
3805+ UniqueLock m (inner);
38113806 size_t offset = set._find_key (key, hashval);
3812- if (offset == (size_t )-1 && m.switch_to_unique ()) {
3813- // we did an unlock/lock, and another thread could have inserted the same key, so we need to
3814- // do a find() again.
3815- offset = set._find_key (key, hashval);
3816- }
38173807 if (offset == (size_t )-1 ) {
38183808 offset = set.prepare_insert (hashval);
38193809 set.lazy_emplace_at (offset, std::forward<F>(f));
@@ -3929,7 +3919,7 @@ class parallel_hash_set {
39293919 template <class K = key_type, class FExists , class FEmplace >
39303920 bool lazy_emplace_l (const key_arg<K>& key, FExists&& fExists , FEmplace&& fEmplace ) {
39313921 size_t hashval = this ->hash (key);
3932- ReadWriteLock m;
3922+ UniqueLock m;
39333923 auto res = this ->find_or_prepare_insert_with_hash (hashval, key, m);
39343924 Inner* inner = std::get<0 >(res);
39353925 if (std::get<2 >(res)) {
@@ -4376,18 +4366,13 @@ class parallel_hash_set {
43764366 }
43774367
43784368 template <class K >
4379- std::tuple<Inner*, size_t , bool > find_or_prepare_insert_with_hash (size_t hashval,
4380- const K& key,
4381- ReadWriteLock & mutexlock) {
4369+ std::tuple<Inner*, size_t , bool > find_or_prepare_insert_with_hash (size_t hashval,
4370+ const K& key,
4371+ UniqueLock & mutexlock) {
43824372 Inner& inner = sets_[subidx (hashval)];
43834373 auto & set = inner.set_ ;
4384- mutexlock = std::move (ReadWriteLock (inner));
4374+ mutexlock = std::move (UniqueLock (inner));
43854375 size_t offset = set._find_key (key, hashval);
4386- if (offset == (size_t )-1 && mutexlock.switch_to_unique ()) {
4387- // we did an unlock/lock, and another thread could have inserted the same key, so we need to
4388- // do a find() again.
4389- offset = set._find_key (key, hashval);
4390- }
43914376 if (offset == (size_t )-1 ) {
43924377 offset = set.prepare_insert (hashval);
43934378 return std::make_tuple (&inner, offset, true );
@@ -4396,7 +4381,7 @@ class parallel_hash_set {
43964381 }
43974382
43984383 template <class K >
4399- std::tuple<Inner*, size_t , bool > find_or_prepare_insert (const K& key, ReadWriteLock & mutexlock) {
4384+ std::tuple<Inner*, size_t , bool > find_or_prepare_insert (const K& key, UniqueLock & mutexlock) {
44004385 return find_or_prepare_insert_with_hash<K>(this ->hash (key), key, mutexlock);
44014386 }
44024387
@@ -4607,7 +4592,7 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, AuxCont, Pol
46074592 template <class K = key_type, class F , class ... Args>
46084593 bool try_emplace_l (K&& k, F&& f, Args&&... args) {
46094594 size_t hashval = this ->hash (k);
4610- ReadWriteLock m;
4595+ UniqueLock m;
46114596 auto res = this ->find_or_prepare_insert_with_hash (hashval, k, m);
46124597 typename Base::Inner* inner = std::get<0 >(res);
46134598
@@ -4631,7 +4616,7 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, AuxCont, Pol
46314616 template <class K = key_type, class ... Args>
46324617 std::pair<typename parallel_hash_map::parallel_hash_set::pointer, bool > try_emplace_p (K&& k, Args&&... args) {
46334618 size_t hashval = this ->hash (k);
4634- ReadWriteLock m;
4619+ UniqueLock m;
46354620 auto res = this ->find_or_prepare_insert_with_hash (hashval, k, m);
46364621 typename Base::Inner* inner = std::get<0 >(res);
46374622 if (std::get<2 >(res)) {
@@ -4661,7 +4646,7 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, AuxCont, Pol
46614646 template <class K , class V >
46624647 std::pair<iterator, bool > insert_or_assign_impl (K&& k, V&& v) {
46634648 size_t hashval = this ->hash (k);
4664- ReadWriteLock m;
4649+ UniqueLock m;
46654650 auto res = this ->find_or_prepare_insert (k, m);
46664651 typename Base::Inner* inner = std::get<0 >(res);
46674652 if (std::get<2 >(res)) {
@@ -4679,7 +4664,7 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, AuxCont, Pol
46794664
46804665 template <class K = key_type, class ... Args>
46814666 std::pair<iterator, bool > try_emplace_impl_with_hash (size_t hashval, K&& k, Args&&... args) {
4682- ReadWriteLock m;
4667+ UniqueLock m;
46834668 auto res = this ->find_or_prepare_insert_with_hash (hashval, k, m);
46844669 typename Base::Inner* inner = std::get<0 >(res);
46854670 if (std::get<2 >(res)) {
0 commit comments