@@ -2563,7 +2563,7 @@ pgstat_bestart(void)
2563
2563
beentry = MyBEEntry ;
2564
2564
do
2565
2565
{
2566
- beentry -> st_changecount ++ ;
2566
+ pgstat_increment_changecount_before ( beentry ) ;
2567
2567
} while ((beentry -> st_changecount & 1 ) == 0 );
2568
2568
2569
2569
beentry -> st_procpid = MyProcPid ;
@@ -2588,8 +2588,7 @@ pgstat_bestart(void)
2588
2588
beentry -> st_appname [NAMEDATALEN - 1 ] = '\0' ;
2589
2589
beentry -> st_activity [pgstat_track_activity_query_size - 1 ] = '\0' ;
2590
2590
2591
- beentry -> st_changecount ++ ;
2592
- Assert ((beentry -> st_changecount & 1 ) == 0 );
2591
+ pgstat_increment_changecount_after (beentry );
2593
2592
2594
2593
/* Update app name to current GUC setting */
2595
2594
if (application_name )
@@ -2624,12 +2623,11 @@ pgstat_beshutdown_hook(int code, Datum arg)
2624
2623
* before and after. We use a volatile pointer here to ensure the
2625
2624
* compiler doesn't try to get cute.
2626
2625
*/
2627
- beentry -> st_changecount ++ ;
2626
+ pgstat_increment_changecount_before ( beentry ) ;
2628
2627
2629
2628
beentry -> st_procpid = 0 ; /* mark invalid */
2630
2629
2631
- beentry -> st_changecount ++ ;
2632
- Assert ((beentry -> st_changecount & 1 ) == 0 );
2630
+ pgstat_increment_changecount_after (beentry );
2633
2631
}
2634
2632
2635
2633
@@ -2666,16 +2664,15 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
2666
2664
* non-disabled state. As our final update, change the state and
2667
2665
* clear fields we will not be updating anymore.
2668
2666
*/
2669
- beentry -> st_changecount ++ ;
2667
+ pgstat_increment_changecount_before ( beentry ) ;
2670
2668
beentry -> st_state = STATE_DISABLED ;
2671
2669
beentry -> st_state_start_timestamp = 0 ;
2672
2670
beentry -> st_activity [0 ] = '\0' ;
2673
2671
beentry -> st_activity_start_timestamp = 0 ;
2674
2672
/* st_xact_start_timestamp and st_waiting are also disabled */
2675
2673
beentry -> st_xact_start_timestamp = 0 ;
2676
2674
beentry -> st_waiting = false;
2677
- beentry -> st_changecount ++ ;
2678
- Assert ((beentry -> st_changecount & 1 ) == 0 );
2675
+ pgstat_increment_changecount_after (beentry );
2679
2676
}
2680
2677
return ;
2681
2678
}
@@ -2695,7 +2692,7 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
2695
2692
/*
2696
2693
* Now update the status entry
2697
2694
*/
2698
- beentry -> st_changecount ++ ;
2695
+ pgstat_increment_changecount_before ( beentry ) ;
2699
2696
2700
2697
beentry -> st_state = state ;
2701
2698
beentry -> st_state_start_timestamp = current_timestamp ;
@@ -2707,8 +2704,7 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
2707
2704
beentry -> st_activity_start_timestamp = start_timestamp ;
2708
2705
}
2709
2706
2710
- beentry -> st_changecount ++ ;
2711
- Assert ((beentry -> st_changecount & 1 ) == 0 );
2707
+ pgstat_increment_changecount_after (beentry );
2712
2708
}
2713
2709
2714
2710
/* ----------
@@ -2734,13 +2730,12 @@ pgstat_report_appname(const char *appname)
2734
2730
* st_changecount before and after. We use a volatile pointer here to
2735
2731
* ensure the compiler doesn't try to get cute.
2736
2732
*/
2737
- beentry -> st_changecount ++ ;
2733
+ pgstat_increment_changecount_before ( beentry ) ;
2738
2734
2739
2735
memcpy ((char * ) beentry -> st_appname , appname , len );
2740
2736
beentry -> st_appname [len ] = '\0' ;
2741
2737
2742
- beentry -> st_changecount ++ ;
2743
- Assert ((beentry -> st_changecount & 1 ) == 0 );
2738
+ pgstat_increment_changecount_after (beentry );
2744
2739
}
2745
2740
2746
2741
/*
@@ -2760,10 +2755,9 @@ pgstat_report_xact_timestamp(TimestampTz tstamp)
2760
2755
* st_changecount before and after. We use a volatile pointer here to
2761
2756
* ensure the compiler doesn't try to get cute.
2762
2757
*/
2763
- beentry -> st_changecount ++ ;
2758
+ pgstat_increment_changecount_before ( beentry ) ;
2764
2759
beentry -> st_xact_start_timestamp = tstamp ;
2765
- beentry -> st_changecount ++ ;
2766
- Assert ((beentry -> st_changecount & 1 ) == 0 );
2760
+ pgstat_increment_changecount_after (beentry );
2767
2761
}
2768
2762
2769
2763
/* ----------
@@ -2839,7 +2833,10 @@ pgstat_read_current_status(void)
2839
2833
*/
2840
2834
for (;;)
2841
2835
{
2842
- int save_changecount = beentry -> st_changecount ;
2836
+ int before_changecount ;
2837
+ int after_changecount ;
2838
+
2839
+ pgstat_save_changecount_before (beentry , before_changecount );
2843
2840
2844
2841
localentry -> backendStatus .st_procpid = beentry -> st_procpid ;
2845
2842
if (localentry -> backendStatus .st_procpid > 0 )
@@ -2856,8 +2853,9 @@ pgstat_read_current_status(void)
2856
2853
localentry -> backendStatus .st_activity = localactivity ;
2857
2854
}
2858
2855
2859
- if (save_changecount == beentry -> st_changecount &&
2860
- (save_changecount & 1 ) == 0 )
2856
+ pgstat_save_changecount_after (beentry , after_changecount );
2857
+ if (before_changecount == after_changecount &&
2858
+ (before_changecount & 1 ) == 0 )
2861
2859
break ;
2862
2860
2863
2861
/* Make sure we can break out of loop if stuck... */
@@ -2927,12 +2925,17 @@ pgstat_get_backend_current_activity(int pid, bool checkUser)
2927
2925
2928
2926
for (;;)
2929
2927
{
2930
- int save_changecount = vbeentry -> st_changecount ;
2928
+ int before_changecount ;
2929
+ int after_changecount ;
2930
+
2931
+ pgstat_save_changecount_before (vbeentry , before_changecount );
2931
2932
2932
2933
found = (vbeentry -> st_procpid == pid );
2933
2934
2934
- if (save_changecount == vbeentry -> st_changecount &&
2935
- (save_changecount & 1 ) == 0 )
2935
+ pgstat_save_changecount_after (vbeentry , after_changecount );
2936
+
2937
+ if (before_changecount == after_changecount &&
2938
+ (before_changecount & 1 ) == 0 )
2936
2939
break ;
2937
2940
2938
2941
/* Make sure we can break out of loop if stuck... */
0 commit comments