@@ -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. */
@@ -186,6 +184,10 @@ static inline bool equal_keys(dshash_table *hash_table,
186
184
#define PARTITION_LOCK (hash_table , i ) \
187
185
(&(hash_table)->control->partitions[(i)].lock)
188
186
187
+ #define ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME (hash_table ) \
188
+ Assert(!LWLockAnyHeldByMe(&(hash_table)->control->partitions[0].lock, \
189
+ DSHASH_NUM_PARTITIONS, sizeof(dshash_partition)))
190
+
189
191
/*
190
192
* Create a new hash table backed by the given dynamic shared area, with the
191
193
* given parameters. The returned object is allocated in backend-local memory
@@ -226,9 +228,6 @@ dshash_create(dsa_area *area, const dshash_parameters *params, void *arg)
226
228
}
227
229
}
228
230
229
- hash_table -> find_locked = false;
230
- hash_table -> find_exclusively_locked = false;
231
-
232
231
/*
233
232
* Set up the initial array of buckets. Our initial size is the same as
234
233
* the number of partitions.
@@ -277,8 +276,6 @@ dshash_attach(dsa_area *area, const dshash_parameters *params,
277
276
hash_table -> params = * params ;
278
277
hash_table -> arg = arg ;
279
278
hash_table -> control = dsa_get_address (area , control );
280
- hash_table -> find_locked = false;
281
- hash_table -> find_exclusively_locked = false;
282
279
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
283
280
284
281
/*
@@ -301,7 +298,7 @@ dshash_attach(dsa_area *area, const dshash_parameters *params,
301
298
void
302
299
dshash_detach (dshash_table * hash_table )
303
300
{
304
- Assert (! hash_table -> find_locked );
301
+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
305
302
306
303
/* The hash table may have been destroyed. Just free local memory. */
307
304
pfree (hash_table );
@@ -392,7 +389,7 @@ dshash_find(dshash_table *hash_table, const void *key, bool exclusive)
392
389
partition = PARTITION_FOR_HASH (hash );
393
390
394
391
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
395
- Assert (! hash_table -> find_locked );
392
+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
396
393
397
394
LWLockAcquire (PARTITION_LOCK (hash_table , partition ),
398
395
exclusive ? LW_EXCLUSIVE : LW_SHARED );
@@ -410,8 +407,6 @@ dshash_find(dshash_table *hash_table, const void *key, bool exclusive)
410
407
else
411
408
{
412
409
/* The caller will free the lock by calling dshash_release_lock. */
413
- hash_table -> find_locked = true;
414
- hash_table -> find_exclusively_locked = exclusive ;
415
410
return ENTRY_FROM_ITEM (item );
416
411
}
417
412
}
@@ -441,7 +436,7 @@ dshash_find_or_insert(dshash_table *hash_table,
441
436
partition = & hash_table -> control -> partitions [partition_index ];
442
437
443
438
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
444
- Assert (! hash_table -> find_locked );
439
+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
445
440
446
441
restart :
447
442
LWLockAcquire (PARTITION_LOCK (hash_table , partition_index ),
@@ -486,8 +481,6 @@ dshash_find_or_insert(dshash_table *hash_table,
486
481
}
487
482
488
483
/* The caller must release the lock with dshash_release_lock. */
489
- hash_table -> find_locked = true;
490
- hash_table -> find_exclusively_locked = true;
491
484
return ENTRY_FROM_ITEM (item );
492
485
}
493
486
@@ -506,7 +499,7 @@ dshash_delete_key(dshash_table *hash_table, const void *key)
506
499
bool found ;
507
500
508
501
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
509
- Assert (! hash_table -> find_locked );
502
+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
510
503
511
504
hash = hash_key (hash_table , key );
512
505
partition = PARTITION_FOR_HASH (hash );
@@ -543,14 +536,10 @@ dshash_delete_entry(dshash_table *hash_table, void *entry)
543
536
size_t partition = PARTITION_FOR_HASH (item -> hash );
544
537
545
538
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
546
- Assert (hash_table -> find_locked );
547
- Assert (hash_table -> find_exclusively_locked );
548
539
Assert (LWLockHeldByMeInMode (PARTITION_LOCK (hash_table , partition ),
549
540
LW_EXCLUSIVE ));
550
541
551
542
delete_item (hash_table , item );
552
- hash_table -> find_locked = false;
553
- hash_table -> find_exclusively_locked = false;
554
543
LWLockRelease (PARTITION_LOCK (hash_table , partition ));
555
544
}
556
545
@@ -564,13 +553,7 @@ dshash_release_lock(dshash_table *hash_table, void *entry)
564
553
size_t partition_index = PARTITION_FOR_HASH (item -> hash );
565
554
566
555
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
567
- Assert (hash_table -> find_locked );
568
- Assert (LWLockHeldByMeInMode (PARTITION_LOCK (hash_table , partition_index ),
569
- hash_table -> find_exclusively_locked
570
- ? LW_EXCLUSIVE : LW_SHARED ));
571
556
572
- hash_table -> find_locked = false;
573
- hash_table -> find_exclusively_locked = false;
574
557
LWLockRelease (PARTITION_LOCK (hash_table , partition_index ));
575
558
}
576
559
@@ -603,7 +586,7 @@ dshash_dump(dshash_table *hash_table)
603
586
size_t j ;
604
587
605
588
Assert (hash_table -> control -> magic == DSHASH_MAGIC );
606
- Assert (! hash_table -> find_locked );
589
+ ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME ( hash_table );
607
590
608
591
for (i = 0 ; i < DSHASH_NUM_PARTITIONS ; ++ i )
609
592
{
0 commit comments