@@ -110,8 +110,6 @@ struct dshash_table
110
110
dshash_table_control * control ; /* Control object in DSM. */
111
111
dsa_pointer * buckets ; /* Current bucket pointers in DSM. */
112
112
size_t size_log2 ; /* log2(number of buckets) */
113
- bool find_locked ; /* Is any partition lock held by 'find'? */
114
- bool find_exclusively_locked ; /* ... exclusively? */
115
113
};
116
114
117
115
/* Given a pointer to an item, find the entry (user data) it holds. */
@@ -194,6 +192,10 @@ static inline bool equal_keys(dshash_table *hash_table,
194
192
#define PARTITION_LOCK (hash_table , i ) \
195
193
(&(hash_table)->control->partitions[(i)].lock)
196
194
195
+ #define ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME (hash_table ) \
196
+ Assert(!LWLockAnyHeldByMe(&(hash_table)->control->partitions[0].lock, \
197
+ DSHASH_NUM_PARTITIONS, sizeof(dshash_partition)))
198
+
197
199
/*
198
200
* Create a new hash table backed by the given dynamic shared area, with the
199
201
* given parameters. The returned object is allocated in backend-local memory
@@ -234,9 +236,6 @@ dshash_create(dsa_area *area, const dshash_parameters *params, void *arg)
234
236
}
235
237
}
236
238
237
- hash_table -> find_locked = false;
238
- hash_table -> find_exclusively_locked = false;
239
-
240
239
/*
241
240
* Set up the initial array of buckets. Our initial size is the same as
242
241
* the number of partitions.
@@ -285,8 +284,6 @@ dshash_attach(dsa_area *area, const dshash_parameters *params,
285
284
hash_table -> params = * params ;
286
285
hash_table -> arg = arg ;
287
286
hash_table -> control = dsa_get_address (area , control );
288
- hash_table -> find_locked = false;
289
- hash_table -> find_exclusively_locked = false;
290
287
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
291
288
292
289
/*
@@ -309,7 +306,7 @@ dshash_attach(dsa_area *area, const dshash_parameters *params,
309
306
void
310
307
dshash_detach (dshash_table * hash_table )
311
308
{
312
- Assert (! hash_table -> find_locked );
309
+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
313
310
314
311
/* The hash table may have been destroyed. Just free local memory. */
315
312
pfree (hash_table );
@@ -400,7 +397,7 @@ dshash_find(dshash_table *hash_table, const void *key, bool exclusive)
400
397
partition = PARTITION_FOR_HASH (hash );
401
398
402
399
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
403
- Assert (! hash_table -> find_locked );
400
+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
404
401
405
402
LWLockAcquire (PARTITION_LOCK (hash_table , partition ),
406
403
exclusive ? LW_EXCLUSIVE : LW_SHARED );
@@ -418,8 +415,6 @@ dshash_find(dshash_table *hash_table, const void *key, bool exclusive)
418
415
else
419
416
{
420
417
/* The caller will free the lock by calling dshash_release_lock. */
421
- hash_table -> find_locked = true;
422
- hash_table -> find_exclusively_locked = exclusive ;
423
418
return ENTRY_FROM_ITEM (item );
424
419
}
425
420
}
@@ -449,7 +444,7 @@ dshash_find_or_insert(dshash_table *hash_table,
449
444
partition = & hash_table -> control -> partitions [partition_index ];
450
445
451
446
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
452
- Assert (! hash_table -> find_locked );
447
+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
453
448
454
449
restart :
455
450
LWLockAcquire (PARTITION_LOCK (hash_table , partition_index ),
@@ -494,8 +489,6 @@ dshash_find_or_insert(dshash_table *hash_table,
494
489
}
495
490
496
491
/* The caller must release the lock with dshash_release_lock. */
497
- hash_table -> find_locked = true;
498
- hash_table -> find_exclusively_locked = true;
499
492
return ENTRY_FROM_ITEM (item );
500
493
}
501
494
@@ -514,7 +507,7 @@ dshash_delete_key(dshash_table *hash_table, const void *key)
514
507
bool found ;
515
508
516
509
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
517
- Assert (! hash_table -> find_locked );
510
+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
518
511
519
512
hash = hash_key (hash_table , key );
520
513
partition = PARTITION_FOR_HASH (hash );
@@ -551,14 +544,10 @@ dshash_delete_entry(dshash_table *hash_table, void *entry)
551
544
size_t partition = PARTITION_FOR_HASH (item -> hash );
552
545
553
546
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
554
- Assert (hash_table -> find_locked );
555
- Assert (hash_table -> find_exclusively_locked );
556
547
Assert (LWLockHeldByMeInMode (PARTITION_LOCK (hash_table , partition ),
557
548
LW_EXCLUSIVE ));
558
549
559
550
delete_item (hash_table , item );
560
- hash_table -> find_locked = false;
561
- hash_table -> find_exclusively_locked = false;
562
551
LWLockRelease (PARTITION_LOCK (hash_table , partition ));
563
552
}
564
553
@@ -572,13 +561,7 @@ dshash_release_lock(dshash_table *hash_table, void *entry)
572
561
size_t partition_index = PARTITION_FOR_HASH (item -> hash );
573
562
574
563
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
575
- Assert (hash_table -> find_locked );
576
- Assert (LWLockHeldByMeInMode (PARTITION_LOCK (hash_table , partition_index ),
577
- hash_table -> find_exclusively_locked
578
- ? LW_EXCLUSIVE : LW_SHARED ));
579
564
580
- hash_table -> find_locked = false;
581
- hash_table -> find_exclusively_locked = false;
582
565
LWLockRelease (PARTITION_LOCK (hash_table , partition_index ));
583
566
}
584
567
@@ -644,7 +627,7 @@ dshash_seq_next(dshash_seq_status *status)
644
627
if (status -> curpartition == -1 )
645
628
{
646
629
Assert (status -> curbucket == 0 );
647
- Assert (! status -> hash_table -> find_locked );
630
+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( status -> hash_table );
648
631
649
632
status -> curpartition = 0 ;
650
633
@@ -702,8 +685,6 @@ dshash_seq_next(dshash_seq_status *status)
702
685
703
686
status -> curitem =
704
687
dsa_get_address (status -> hash_table -> area , next_item_pointer );
705
- status -> hash_table -> find_locked = true;
706
- status -> hash_table -> find_exclusively_locked = status -> exclusive ;
707
688
708
689
/*
709
690
* The caller may delete the item. Store the next item in case of
@@ -722,9 +703,6 @@ dshash_seq_next(dshash_seq_status *status)
722
703
void
723
704
dshash_seq_term (dshash_seq_status * status )
724
705
{
725
- status -> hash_table -> find_locked = false;
726
- status -> hash_table -> find_exclusively_locked = false;
727
-
728
706
if (status -> curpartition >= 0 )
729
707
LWLockRelease (PARTITION_LOCK (status -> hash_table , status -> curpartition ));
730
708
}
@@ -743,8 +721,6 @@ dshash_delete_current(dshash_seq_status *status)
743
721
744
722
Assert (status -> exclusive );
745
723
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
746
- Assert (hash_table -> find_locked );
747
- Assert (hash_table -> find_exclusively_locked );
748
724
Assert (LWLockHeldByMeInMode (PARTITION_LOCK (hash_table , partition ),
749
725
LW_EXCLUSIVE ));
750
726
@@ -762,7 +738,7 @@ dshash_dump(dshash_table *hash_table)
762
738
size_t j ;
763
739
764
740
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
765
- Assert (! hash_table -> find_locked );
741
+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
766
742
767
743
for (i = 0 ; i < DSHASH_NUM_PARTITIONS ; ++ i )
768
744
{
0 commit comments