@@ -110,8 +110,6 @@ struct dshash_table
110110 dshash_table_control * control ; /* Control object in DSM. */
111111 dsa_pointer * buckets ; /* Current bucket pointers in DSM. */
112112 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? */
115113};
116114
117115/* 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,
194192#define PARTITION_LOCK (hash_table , i ) \
195193 (&(hash_table)->control->partitions[(i)].lock)
196194
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+
197199/*
198200 * Create a new hash table backed by the given dynamic shared area, with the
199201 * 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)
234236 }
235237 }
236238
237- hash_table -> find_locked = false;
238- hash_table -> find_exclusively_locked = false;
239-
240239 /*
241240 * Set up the initial array of buckets. Our initial size is the same as
242241 * the number of partitions.
@@ -285,8 +284,6 @@ dshash_attach(dsa_area *area, const dshash_parameters *params,
285284 hash_table -> params = * params ;
286285 hash_table -> arg = arg ;
287286 hash_table -> control = dsa_get_address (area , control );
288- hash_table -> find_locked = false;
289- hash_table -> find_exclusively_locked = false;
290287 Assert (hash_table -> control -> magic == DSHASH_MAGIC );
291288
292289 /*
@@ -309,7 +306,7 @@ dshash_attach(dsa_area *area, const dshash_parameters *params,
309306void
310307dshash_detach (dshash_table * hash_table )
311308{
312- Assert (! hash_table -> find_locked );
309+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
313310
314311 /* The hash table may have been destroyed. Just free local memory. */
315312 pfree (hash_table );
@@ -400,7 +397,7 @@ dshash_find(dshash_table *hash_table, const void *key, bool exclusive)
400397 partition = PARTITION_FOR_HASH (hash );
401398
402399 Assert (hash_table -> control -> magic == DSHASH_MAGIC );
403- Assert (! hash_table -> find_locked );
400+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
404401
405402 LWLockAcquire (PARTITION_LOCK (hash_table , partition ),
406403 exclusive ? LW_EXCLUSIVE : LW_SHARED );
@@ -418,8 +415,6 @@ dshash_find(dshash_table *hash_table, const void *key, bool exclusive)
418415 else
419416 {
420417 /* The caller will free the lock by calling dshash_release_lock. */
421- hash_table -> find_locked = true;
422- hash_table -> find_exclusively_locked = exclusive ;
423418 return ENTRY_FROM_ITEM (item );
424419 }
425420}
@@ -449,7 +444,7 @@ dshash_find_or_insert(dshash_table *hash_table,
449444 partition = & hash_table -> control -> partitions [partition_index ];
450445
451446 Assert (hash_table -> control -> magic == DSHASH_MAGIC );
452- Assert (! hash_table -> find_locked );
447+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
453448
454449restart :
455450 LWLockAcquire (PARTITION_LOCK (hash_table , partition_index ),
@@ -494,8 +489,6 @@ dshash_find_or_insert(dshash_table *hash_table,
494489 }
495490
496491 /* The caller must release the lock with dshash_release_lock. */
497- hash_table -> find_locked = true;
498- hash_table -> find_exclusively_locked = true;
499492 return ENTRY_FROM_ITEM (item );
500493}
501494
@@ -514,7 +507,7 @@ dshash_delete_key(dshash_table *hash_table, const void *key)
514507 bool found ;
515508
516509 Assert (hash_table -> control -> magic == DSHASH_MAGIC );
517- Assert (! hash_table -> find_locked );
510+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
518511
519512 hash = hash_key (hash_table , key );
520513 partition = PARTITION_FOR_HASH (hash );
@@ -551,14 +544,10 @@ dshash_delete_entry(dshash_table *hash_table, void *entry)
551544 size_t partition = PARTITION_FOR_HASH (item -> hash );
552545
553546 Assert (hash_table -> control -> magic == DSHASH_MAGIC );
554- Assert (hash_table -> find_locked );
555- Assert (hash_table -> find_exclusively_locked );
556547 Assert (LWLockHeldByMeInMode (PARTITION_LOCK (hash_table , partition ),
557548 LW_EXCLUSIVE ));
558549
559550 delete_item (hash_table , item );
560- hash_table -> find_locked = false;
561- hash_table -> find_exclusively_locked = false;
562551 LWLockRelease (PARTITION_LOCK (hash_table , partition ));
563552}
564553
@@ -572,13 +561,7 @@ dshash_release_lock(dshash_table *hash_table, void *entry)
572561 size_t partition_index = PARTITION_FOR_HASH (item -> hash );
573562
574563 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 ));
579564
580- hash_table -> find_locked = false;
581- hash_table -> find_exclusively_locked = false;
582565 LWLockRelease (PARTITION_LOCK (hash_table , partition_index ));
583566}
584567
@@ -644,7 +627,7 @@ dshash_seq_next(dshash_seq_status *status)
644627 if (status -> curpartition == -1 )
645628 {
646629 Assert (status -> curbucket == 0 );
647- Assert (! status -> hash_table -> find_locked );
630+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( status -> hash_table );
648631
649632 status -> curpartition = 0 ;
650633
@@ -702,8 +685,6 @@ dshash_seq_next(dshash_seq_status *status)
702685
703686 status -> curitem =
704687 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 ;
707688
708689 /*
709690 * The caller may delete the item. Store the next item in case of
@@ -722,9 +703,6 @@ dshash_seq_next(dshash_seq_status *status)
722703void
723704dshash_seq_term (dshash_seq_status * status )
724705{
725- status -> hash_table -> find_locked = false;
726- status -> hash_table -> find_exclusively_locked = false;
727-
728706 if (status -> curpartition >= 0 )
729707 LWLockRelease (PARTITION_LOCK (status -> hash_table , status -> curpartition ));
730708}
@@ -743,8 +721,6 @@ dshash_delete_current(dshash_seq_status *status)
743721
744722 Assert (status -> exclusive );
745723 Assert (hash_table -> control -> magic == DSHASH_MAGIC );
746- Assert (hash_table -> find_locked );
747- Assert (hash_table -> find_exclusively_locked );
748724 Assert (LWLockHeldByMeInMode (PARTITION_LOCK (hash_table , partition ),
749725 LW_EXCLUSIVE ));
750726
@@ -762,7 +738,7 @@ dshash_dump(dshash_table *hash_table)
762738 size_t j ;
763739
764740 Assert (hash_table -> control -> magic == DSHASH_MAGIC );
765- Assert (! hash_table -> find_locked );
741+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
766742
767743 for (i = 0 ; i < DSHASH_NUM_PARTITIONS ; ++ i )
768744 {
0 commit comments