@@ -216,9 +216,6 @@ InitDeadLockChecking(void)
216
216
DeadLockState
217
217
DeadLockCheck (PGPROC * proc )
218
218
{
219
- int i ,
220
- j ;
221
-
222
219
/* Initialize to "no constraints" */
223
220
nCurConstraints = 0 ;
224
221
nPossibleConstraints = 0 ;
@@ -246,26 +243,23 @@ DeadLockCheck(PGPROC *proc)
246
243
}
247
244
248
245
/* Apply any needed rearrangements of wait queues */
249
- for (i = 0 ; i < nWaitOrders ; i ++ )
246
+ for (int i = 0 ; i < nWaitOrders ; i ++ )
250
247
{
251
248
LOCK * lock = waitOrders [i ].lock ;
252
249
PGPROC * * procs = waitOrders [i ].procs ;
253
250
int nProcs = waitOrders [i ].nProcs ;
254
- PROC_QUEUE * waitQueue = & ( lock -> waitProcs ) ;
251
+ dclist_head * waitQueue = & lock -> waitProcs ;
255
252
256
- Assert (nProcs == waitQueue -> size );
253
+ Assert (nProcs == dclist_count ( waitQueue ) );
257
254
258
255
#ifdef DEBUG_DEADLOCK
259
256
PrintLockQueue (lock , "DeadLockCheck:" );
260
257
#endif
261
258
262
259
/* Reset the queue and re-add procs in the desired order */
263
- ProcQueueInit (waitQueue );
264
- for (j = 0 ; j < nProcs ; j ++ )
265
- {
266
- SHMQueueInsertBefore (& (waitQueue -> links ), & (procs [j ]-> links ));
267
- waitQueue -> size ++ ;
268
- }
260
+ dclist_init (waitQueue );
261
+ for (int j = 0 ; j < nProcs ; j ++ )
262
+ dclist_push_tail (waitQueue , & procs [j ]-> links );
269
263
270
264
#ifdef DEBUG_DEADLOCK
271
265
PrintLockQueue (lock , "rearranged to:" );
@@ -544,11 +538,8 @@ FindLockCycleRecurseMember(PGPROC *checkProc,
544
538
{
545
539
PGPROC * proc ;
546
540
LOCK * lock = checkProc -> waitLock ;
547
- PROCLOCK * proclock ;
548
- SHM_QUEUE * procLocks ;
541
+ dlist_iter proclock_iter ;
549
542
LockMethod lockMethodTable ;
550
- PROC_QUEUE * waitQueue ;
551
- int queue_size ;
552
543
int conflictMask ;
553
544
int i ;
554
545
int numLockModes ,
@@ -571,13 +562,9 @@ FindLockCycleRecurseMember(PGPROC *checkProc,
571
562
* Scan for procs that already hold conflicting locks. These are "hard"
572
563
* edges in the waits-for graph.
573
564
*/
574
- procLocks = & (lock -> procLocks );
575
-
576
- proclock = (PROCLOCK * ) SHMQueueNext (procLocks , procLocks ,
577
- offsetof(PROCLOCK , lockLink ));
578
-
579
- while (proclock )
565
+ dlist_foreach (proclock_iter , & lock -> procLocks )
580
566
{
567
+ PROCLOCK * proclock = dlist_container (PROCLOCK , lockLink , proclock_iter .cur );
581
568
PGPROC * leader ;
582
569
583
570
proc = proclock -> tag .myProc ;
@@ -636,9 +623,6 @@ FindLockCycleRecurseMember(PGPROC *checkProc,
636
623
}
637
624
}
638
625
}
639
-
640
- proclock = (PROCLOCK * ) SHMQueueNext (procLocks , & proclock -> lockLink ,
641
- offsetof(PROCLOCK , lockLink ));
642
626
}
643
627
644
628
/*
@@ -660,8 +644,7 @@ FindLockCycleRecurseMember(PGPROC *checkProc,
660
644
{
661
645
/* Use the given hypothetical wait queue order */
662
646
PGPROC * * procs = waitOrders [i ].procs ;
663
-
664
- queue_size = waitOrders [i ].nProcs ;
647
+ int queue_size = waitOrders [i ].nProcs ;
665
648
666
649
for (i = 0 ; i < queue_size ; i ++ )
667
650
{
@@ -711,9 +694,11 @@ FindLockCycleRecurseMember(PGPROC *checkProc,
711
694
else
712
695
{
713
696
PGPROC * lastGroupMember = NULL ;
697
+ dlist_iter proc_iter ;
698
+ dclist_head * waitQueue ;
714
699
715
700
/* Use the true lock wait queue order */
716
- waitQueue = & ( lock -> waitProcs ) ;
701
+ waitQueue = & lock -> waitProcs ;
717
702
718
703
/*
719
704
* Find the last member of the lock group that is present in the wait
@@ -726,26 +711,25 @@ FindLockCycleRecurseMember(PGPROC *checkProc,
726
711
lastGroupMember = checkProc ;
727
712
else
728
713
{
729
- proc = (PGPROC * ) waitQueue -> links .next ;
730
- queue_size = waitQueue -> size ;
731
- while (queue_size -- > 0 )
714
+ dclist_foreach (proc_iter , waitQueue )
732
715
{
716
+ proc = dlist_container (PGPROC , links , proc_iter .cur );
717
+
733
718
if (proc -> lockGroupLeader == checkProcLeader )
734
719
lastGroupMember = proc ;
735
- proc = (PGPROC * ) proc -> links .next ;
736
720
}
737
721
Assert (lastGroupMember != NULL );
738
722
}
739
723
740
724
/*
741
725
* OK, now rescan (or scan) the queue to identify the soft conflicts.
742
726
*/
743
- queue_size = waitQueue -> size ;
744
- proc = (PGPROC * ) waitQueue -> links .next ;
745
- while (queue_size -- > 0 )
727
+ dclist_foreach (proc_iter , waitQueue )
746
728
{
747
729
PGPROC * leader ;
748
730
731
+ proc = dlist_container (PGPROC , links , proc_iter .cur );
732
+
749
733
leader = proc -> lockGroupLeader == NULL ? proc :
750
734
proc -> lockGroupLeader ;
751
735
@@ -779,8 +763,6 @@ FindLockCycleRecurseMember(PGPROC *checkProc,
779
763
return true;
780
764
}
781
765
}
782
-
783
- proc = (PGPROC * ) proc -> links .next ;
784
766
}
785
767
}
786
768
@@ -832,8 +814,8 @@ ExpandConstraints(EDGE *constraints,
832
814
/* No, so allocate a new list */
833
815
waitOrders [nWaitOrders ].lock = lock ;
834
816
waitOrders [nWaitOrders ].procs = waitOrderProcs + nWaitOrderProcs ;
835
- waitOrders [nWaitOrders ].nProcs = lock -> waitProcs . size ;
836
- nWaitOrderProcs += lock -> waitProcs . size ;
817
+ waitOrders [nWaitOrders ].nProcs = dclist_count ( & lock -> waitProcs ) ;
818
+ nWaitOrderProcs += dclist_count ( & lock -> waitProcs ) ;
837
819
Assert (nWaitOrderProcs <= MaxBackends );
838
820
839
821
/*
@@ -880,23 +862,25 @@ TopoSort(LOCK *lock,
880
862
int nConstraints ,
881
863
PGPROC * * ordering ) /* output argument */
882
864
{
883
- PROC_QUEUE * waitQueue = & ( lock -> waitProcs ) ;
884
- int queue_size = waitQueue -> size ;
865
+ dclist_head * waitQueue = & lock -> waitProcs ;
866
+ int queue_size = dclist_count ( waitQueue ) ;
885
867
PGPROC * proc ;
886
868
int i ,
887
869
j ,
888
870
jj ,
889
871
k ,
890
872
kk ,
891
873
last ;
874
+ dlist_iter proc_iter ;
892
875
893
876
/* First, fill topoProcs[] array with the procs in their current order */
894
- proc = ( PGPROC * ) waitQueue -> links . next ;
895
- for ( i = 0 ; i < queue_size ; i ++ )
877
+ i = 0 ;
878
+ dclist_foreach ( proc_iter , waitQueue )
896
879
{
897
- topoProcs [ i ] = proc ;
898
- proc = ( PGPROC * ) proc -> links . next ;
880
+ proc = dlist_container ( PGPROC , links , proc_iter . cur ) ;
881
+ topoProcs [ i ++ ] = proc ;
899
882
}
883
+ Assert (i == queue_size );
900
884
901
885
/*
902
886
* Scan the constraints, and for each proc in the array, generate a count
@@ -1066,17 +1050,16 @@ TopoSort(LOCK *lock,
1066
1050
static void
1067
1051
PrintLockQueue (LOCK * lock , const char * info )
1068
1052
{
1069
- PROC_QUEUE * waitQueue = & (lock -> waitProcs );
1070
- int queue_size = waitQueue -> size ;
1071
- PGPROC * proc ;
1072
- int i ;
1053
+ dclist_head * waitQueue = & lock -> waitProcs ;
1054
+ dlist_iter proc_iter ;
1073
1055
1074
1056
printf ("%s lock %p queue " , info , lock );
1075
- proc = ( PGPROC * ) waitQueue -> links . next ;
1076
- for ( i = 0 ; i < queue_size ; i ++ )
1057
+
1058
+ dclist_foreach ( proc_iter , waitQueue )
1077
1059
{
1060
+ PGPROC * proc = dlist_container (PGPROC , links , proc_iter .cur );
1061
+
1078
1062
printf (" %d" , proc -> pid );
1079
- proc = (PGPROC * ) proc -> links .next ;
1080
1063
}
1081
1064
printf ("\n" );
1082
1065
fflush (stdout );
0 commit comments