@@ -4458,6 +4458,8 @@ PgstatCollectorMain(int argc, char *argv[])
4458
4458
int len ;
4459
4459
PgStat_Msg msg ;
4460
4460
int wr ;
4461
+ WaitEvent event ;
4462
+ WaitEventSet * wes ;
4461
4463
4462
4464
/*
4463
4465
* Ignore all signals usually bound to some action in the postmaster,
@@ -4485,6 +4487,12 @@ PgstatCollectorMain(int argc, char *argv[])
4485
4487
pgStatRunningInCollector = true;
4486
4488
pgStatDBHash = pgstat_read_statsfiles (InvalidOid , true, true);
4487
4489
4490
+ /* Prepare to wait for our latch or data in our socket. */
4491
+ wes = CreateWaitEventSet (CurrentMemoryContext , 3 );
4492
+ AddWaitEventToSet (wes , WL_LATCH_SET , PGINVALID_SOCKET , MyLatch , NULL );
4493
+ AddWaitEventToSet (wes , WL_POSTMASTER_DEATH , PGINVALID_SOCKET , NULL , NULL );
4494
+ AddWaitEventToSet (wes , WL_SOCKET_READABLE , pgStatSock , NULL , NULL );
4495
+
4488
4496
/*
4489
4497
* Loop to process messages until we get SIGQUIT or detect ungraceful
4490
4498
* death of our parent postmaster.
@@ -4672,10 +4680,7 @@ PgstatCollectorMain(int argc, char *argv[])
4672
4680
4673
4681
/* Sleep until there's something to do */
4674
4682
#ifndef WIN32
4675
- wr = WaitLatchOrSocket (MyLatch ,
4676
- WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_SOCKET_READABLE ,
4677
- pgStatSock , -1L ,
4678
- WAIT_EVENT_PGSTAT_MAIN );
4683
+ wr = WaitEventSetWait (wes , -1L , & event , 1 , WAIT_EVENT_PGSTAT_MAIN );
4679
4684
#else
4680
4685
4681
4686
/*
@@ -4688,18 +4693,15 @@ PgstatCollectorMain(int argc, char *argv[])
4688
4693
* to not provoke "using stale statistics" complaints from
4689
4694
* backend_read_statsfile.
4690
4695
*/
4691
- wr = WaitLatchOrSocket (MyLatch ,
4692
- WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_SOCKET_READABLE | WL_TIMEOUT ,
4693
- pgStatSock ,
4694
- 2 * 1000L /* msec */ ,
4695
- WAIT_EVENT_PGSTAT_MAIN );
4696
+ wr = WaitEventSetWait (wes , 2 * 1000L /* msec */ , & event , 1 ,
4697
+ WAIT_EVENT_PGSTAT_MAIN );
4696
4698
#endif
4697
4699
4698
4700
/*
4699
4701
* Emergency bailout if postmaster has died. This is to avoid the
4700
4702
* necessity for manual cleanup of all postmaster children.
4701
4703
*/
4702
- if (wr & WL_POSTMASTER_DEATH )
4704
+ if (wr == 1 && event . events == WL_POSTMASTER_DEATH )
4703
4705
break ;
4704
4706
} /* end of outer loop */
4705
4707
@@ -4708,6 +4710,8 @@ PgstatCollectorMain(int argc, char *argv[])
4708
4710
*/
4709
4711
pgstat_write_statsfiles (true, true);
4710
4712
4713
+ FreeWaitEventSet (wes );
4714
+
4711
4715
exit (0 );
4712
4716
}
4713
4717
0 commit comments