@@ -70,7 +70,7 @@ typedef struct BTParallelScanDescData
70
70
BTPS_State btps_pageStatus ; /* indicates whether next page is
71
71
* available for scan. see above for
72
72
* possible states of parallel scan. */
73
- slock_t btps_mutex ; /* protects above variables, btps_arrElems */
73
+ LWLock btps_lock ; /* protects shared parallel state */
74
74
ConditionVariable btps_cv ; /* used to synchronize parallel scan */
75
75
76
76
/*
@@ -554,7 +554,8 @@ btinitparallelscan(void *target)
554
554
{
555
555
BTParallelScanDesc bt_target = (BTParallelScanDesc ) target ;
556
556
557
- SpinLockInit (& bt_target -> btps_mutex );
557
+ LWLockInitialize (& bt_target -> btps_lock ,
558
+ LWTRANCHE_PARALLEL_BTREE_SCAN );
558
559
bt_target -> btps_nextScanPage = InvalidBlockNumber ;
559
560
bt_target -> btps_lastCurrPage = InvalidBlockNumber ;
560
561
bt_target -> btps_pageStatus = BTPARALLEL_NOT_INITIALIZED ;
@@ -576,15 +577,15 @@ btparallelrescan(IndexScanDesc scan)
576
577
parallel_scan -> ps_offset );
577
578
578
579
/*
579
- * In theory, we don't need to acquire the spinlock here, because there
580
+ * In theory, we don't need to acquire the LWLock here, because there
580
581
* shouldn't be any other workers running at this point, but we do so for
581
582
* consistency.
582
583
*/
583
- SpinLockAcquire (& btscan -> btps_mutex );
584
+ LWLockAcquire (& btscan -> btps_lock , LW_EXCLUSIVE );
584
585
btscan -> btps_nextScanPage = InvalidBlockNumber ;
585
586
btscan -> btps_lastCurrPage = InvalidBlockNumber ;
586
587
btscan -> btps_pageStatus = BTPARALLEL_NOT_INITIALIZED ;
587
- SpinLockRelease (& btscan -> btps_mutex );
588
+ LWLockRelease (& btscan -> btps_lock );
588
589
}
589
590
590
591
/*
@@ -655,7 +656,7 @@ _bt_parallel_seize(IndexScanDesc scan, BlockNumber *next_scan_page,
655
656
656
657
while (1 )
657
658
{
658
- SpinLockAcquire (& btscan -> btps_mutex );
659
+ LWLockAcquire (& btscan -> btps_lock , LW_EXCLUSIVE );
659
660
660
661
if (btscan -> btps_pageStatus == BTPARALLEL_DONE )
661
662
{
@@ -717,7 +718,7 @@ _bt_parallel_seize(IndexScanDesc scan, BlockNumber *next_scan_page,
717
718
* last_curr_page = btscan -> btps_lastCurrPage ;
718
719
exit_loop = true;
719
720
}
720
- SpinLockRelease (& btscan -> btps_mutex );
721
+ LWLockRelease (& btscan -> btps_lock );
721
722
if (exit_loop || !status )
722
723
break ;
723
724
ConditionVariableSleep (& btscan -> btps_cv , WAIT_EVENT_BTREE_PAGE );
@@ -761,11 +762,11 @@ _bt_parallel_release(IndexScanDesc scan, BlockNumber next_scan_page,
761
762
btscan = (BTParallelScanDesc ) OffsetToPointer (parallel_scan ,
762
763
parallel_scan -> ps_offset );
763
764
764
- SpinLockAcquire (& btscan -> btps_mutex );
765
+ LWLockAcquire (& btscan -> btps_lock , LW_EXCLUSIVE );
765
766
btscan -> btps_nextScanPage = next_scan_page ;
766
767
btscan -> btps_lastCurrPage = curr_page ;
767
768
btscan -> btps_pageStatus = BTPARALLEL_IDLE ;
768
- SpinLockRelease (& btscan -> btps_mutex );
769
+ LWLockRelease (& btscan -> btps_lock );
769
770
ConditionVariableSignal (& btscan -> btps_cv );
770
771
}
771
772
@@ -804,14 +805,14 @@ _bt_parallel_done(IndexScanDesc scan)
804
805
* Mark the parallel scan as done, unless some other process did so
805
806
* already
806
807
*/
807
- SpinLockAcquire (& btscan -> btps_mutex );
808
+ LWLockAcquire (& btscan -> btps_lock , LW_EXCLUSIVE );
808
809
Assert (btscan -> btps_pageStatus != BTPARALLEL_NEED_PRIMSCAN );
809
810
if (btscan -> btps_pageStatus != BTPARALLEL_DONE )
810
811
{
811
812
btscan -> btps_pageStatus = BTPARALLEL_DONE ;
812
813
status_changed = true;
813
814
}
814
- SpinLockRelease (& btscan -> btps_mutex );
815
+ LWLockRelease (& btscan -> btps_lock );
815
816
816
817
/* wake up all the workers associated with this parallel scan */
817
818
if (status_changed )
@@ -838,7 +839,7 @@ _bt_parallel_primscan_schedule(IndexScanDesc scan, BlockNumber curr_page)
838
839
btscan = (BTParallelScanDesc ) OffsetToPointer (parallel_scan ,
839
840
parallel_scan -> ps_offset );
840
841
841
- SpinLockAcquire (& btscan -> btps_mutex );
842
+ LWLockAcquire (& btscan -> btps_lock , LW_EXCLUSIVE );
842
843
if (btscan -> btps_lastCurrPage == curr_page &&
843
844
btscan -> btps_pageStatus == BTPARALLEL_IDLE )
844
845
{
@@ -854,7 +855,7 @@ _bt_parallel_primscan_schedule(IndexScanDesc scan, BlockNumber curr_page)
854
855
btscan -> btps_arrElems [i ] = array -> cur_elem ;
855
856
}
856
857
}
857
- SpinLockRelease (& btscan -> btps_mutex );
858
+ LWLockRelease (& btscan -> btps_lock );
858
859
}
859
860
860
861
/*
0 commit comments