@@ -1323,6 +1323,29 @@ where
13231323 return ;
13241324 }
13251325
1326+ if self
1327+ . minimum_capacity_var ( )
1328+ . fetch_update ( AcqRel , Acquire , |lock_state| {
1329+ if lock_state >= RESIZING {
1330+ None
1331+ } else {
1332+ Some ( lock_state + RESIZING )
1333+ }
1334+ } )
1335+ . is_err ( )
1336+ {
1337+ // The bucket array is being replaced with a new one.
1338+ return ;
1339+ }
1340+ let _lock_guard = ExitGuard :: new ( ( ) , |( ) | {
1341+ self . minimum_capacity_var ( ) . fetch_sub ( RESIZING , Release ) ;
1342+ } ) ;
1343+
1344+ if self . bucket_array_var ( ) . load ( Acquire , guard) != current_array_ptr {
1345+ // Resized in the meantime.
1346+ return ;
1347+ }
1348+
13261349 let minimum_capacity = self . minimum_capacity ( ) ;
13271350 let capacity = current_array. num_slots ( ) ;
13281351 let estimated_num_entries = Self :: sample ( current_array, sampling_index) ;
@@ -1362,28 +1385,6 @@ where
13621385 return ;
13631386 }
13641387
1365- if self
1366- . minimum_capacity_var ( )
1367- . fetch_update ( AcqRel , Acquire , |lock_state| {
1368- if lock_state >= RESIZING {
1369- None
1370- } else {
1371- Some ( lock_state + RESIZING )
1372- }
1373- } )
1374- . is_err ( )
1375- {
1376- // The bucket array is being replaced with a new one.
1377- return ;
1378- }
1379- let _lock_guard = ExitGuard :: new ( ( ) , |( ) | {
1380- self . minimum_capacity_var ( ) . fetch_sub ( RESIZING , Release ) ;
1381- } ) ;
1382-
1383- if self . bucket_array_var ( ) . load ( Acquire , guard) != current_array_ptr {
1384- return ;
1385- }
1386-
13871388 if try_drop_table {
13881389 // Try to drop the hash table with all the buckets locked.
13891390 let mut writer_guard = ExitGuard :: new ( ( 0 , false ) , |( len, success) : ( usize , bool ) | {
0 commit comments