@@ -2616,7 +2616,6 @@ class parallel_hash_set
2616
2616
using UniqueLock = typename Lockable::UniqueLock;
2617
2617
using SharedLock = typename Lockable::SharedLock;
2618
2618
using ReadWriteLock = typename Lockable::ReadWriteLock;
2619
-
2620
2619
2621
2620
// --------------------------------------------------------------------
2622
2621
struct Inner : public Lockable
@@ -3178,14 +3177,9 @@ class parallel_hash_set
3178
3177
{
3179
3178
Inner& inner = sets_[subidx (hashval)];
3180
3179
auto & set = inner.set_ ;
3181
- ReadWriteLock m (inner);
3180
+ UniqueLock m (inner);
3182
3181
3183
3182
size_t offset = set._find_key (key, hashval);
3184
- if (offset == (size_t )-1 && m.switch_to_unique ()) {
3185
- // we did an unlock/lock, and another thread could have inserted the same key, so we need to
3186
- // do a find() again.
3187
- offset = set._find_key (key, hashval);
3188
- }
3189
3183
if (offset == (size_t )-1 ) {
3190
3184
offset = set.prepare_insert (hashval);
3191
3185
set.emplace_at (offset, std::forward<Args>(args)...);
@@ -3268,13 +3262,8 @@ class parallel_hash_set
3268
3262
iterator lazy_emplace_with_hash (const key_arg<K>& key, size_t hashval, F&& f) {
3269
3263
Inner& inner = sets_[subidx (hashval)];
3270
3264
auto & set = inner.set_ ;
3271
- ReadWriteLock m (inner);
3265
+ UniqueLock m (inner);
3272
3266
size_t offset = set._find_key (key, hashval);
3273
- if (offset == (size_t )-1 && m.switch_to_unique ()) {
3274
- // we did an unlock/lock, and another thread could have inserted the same key, so we need to
3275
- // do a find() again.
3276
- offset = set._find_key (key, hashval);
3277
- }
3278
3267
if (offset == (size_t )-1 ) {
3279
3268
offset = set.prepare_insert (hashval);
3280
3269
set.lazy_emplace_at (offset, std::forward<F>(f));
@@ -3389,7 +3378,7 @@ class parallel_hash_set
3389
3378
template <class K = key_type, class FExists , class FEmplace >
3390
3379
bool lazy_emplace_l (const key_arg<K>& key, FExists&& fExists , FEmplace&& fEmplace ) {
3391
3380
size_t hashval = this ->hash (key);
3392
- ReadWriteLock m;
3381
+ UniqueLock m;
3393
3382
auto res = this ->find_or_prepare_insert_with_hash (hashval, key, m);
3394
3383
Inner* inner = std::get<0 >(res);
3395
3384
if (std::get<2 >(res)) {
@@ -3843,16 +3832,11 @@ class parallel_hash_set
3843
3832
3844
3833
template <class K >
3845
3834
std::tuple<Inner*, size_t , bool >
3846
- find_or_prepare_insert_with_hash (size_t hashval, const K& key, ReadWriteLock &mutexlock) {
3835
+ find_or_prepare_insert_with_hash (size_t hashval, const K& key, UniqueLock &mutexlock) {
3847
3836
Inner& inner = sets_[subidx (hashval)];
3848
3837
auto & set = inner.set_ ;
3849
- mutexlock = std::move (ReadWriteLock (inner));
3838
+ mutexlock = std::move (UniqueLock (inner));
3850
3839
size_t offset = set._find_key (key, hashval);
3851
- if (offset == (size_t )-1 && mutexlock.switch_to_unique ()) {
3852
- // we did an unlock/lock, and another thread could have inserted the same key, so we need to
3853
- // do a find() again.
3854
- offset = set._find_key (key, hashval);
3855
- }
3856
3840
if (offset == (size_t )-1 ) {
3857
3841
offset = set.prepare_insert (hashval);
3858
3842
return std::make_tuple (&inner, offset, true );
@@ -3862,7 +3846,7 @@ class parallel_hash_set
3862
3846
3863
3847
template <class K >
3864
3848
std::tuple<Inner*, size_t , bool >
3865
- find_or_prepare_insert (const K& key, ReadWriteLock &mutexlock) {
3849
+ find_or_prepare_insert (const K& key, UniqueLock &mutexlock) {
3866
3850
return find_or_prepare_insert_with_hash<K>(this ->hash (key), key, mutexlock);
3867
3851
}
3868
3852
@@ -4084,7 +4068,7 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, Policy, Hash
4084
4068
template <class K = key_type, class F , class ... Args>
4085
4069
bool try_emplace_l (K&& k, F&& f, Args&&... args) {
4086
4070
size_t hashval = this ->hash (k);
4087
- ReadWriteLock m;
4071
+ UniqueLock m;
4088
4072
auto res = this ->find_or_prepare_insert_with_hash (hashval, k, m);
4089
4073
typename Base::Inner *inner = std::get<0 >(res);
4090
4074
if (std::get<2 >(res)) {
@@ -4105,7 +4089,7 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, Policy, Hash
4105
4089
template <class K = key_type, class ... Args>
4106
4090
std::pair<typename parallel_hash_map::parallel_hash_set::pointer, bool > try_emplace_p (K&& k, Args&&... args) {
4107
4091
size_t hashval = this ->hash (k);
4108
- ReadWriteLock m;
4092
+ UniqueLock m;
4109
4093
auto res = this ->find_or_prepare_insert_with_hash (hashval, k, m);
4110
4094
typename Base::Inner *inner = std::get<0 >(res);
4111
4095
if (std::get<2 >(res)) {
@@ -4135,7 +4119,7 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, Policy, Hash
4135
4119
template <class K , class V >
4136
4120
std::pair<iterator, bool > insert_or_assign_impl (K&& k, V&& v) {
4137
4121
size_t hashval = this ->hash (k);
4138
- ReadWriteLock m;
4122
+ UniqueLock m;
4139
4123
auto res = this ->find_or_prepare_insert_with_hash (hashval, k, m);
4140
4124
typename Base::Inner *inner = std::get<0 >(res);
4141
4125
if (std::get<2 >(res)) {
@@ -4155,7 +4139,7 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, Policy, Hash
4155
4139
4156
4140
template <class K = key_type, class ... Args>
4157
4141
std::pair<iterator, bool > try_emplace_impl_with_hash (size_t hashval, K&& k, Args&&... args) {
4158
- ReadWriteLock m;
4142
+ UniqueLock m;
4159
4143
auto res = this ->find_or_prepare_insert_with_hash (hashval, k, m);
4160
4144
typename Base::Inner *inner = std::get<0 >(res);
4161
4145
if (std::get<2 >(res)) {
0 commit comments