@@ -4458,6 +4458,8 @@ PgstatCollectorMain(int argc, char *argv[])
44584458int len ;
44594459PgStat_Msg msg ;
44604460int wr ;
4461+ WaitEvent event ;
4462+ WaitEventSet * wes ;
44614463
44624464/*
44634465 * Ignore all signals usually bound to some action in the postmaster,
@@ -4485,6 +4487,12 @@ PgstatCollectorMain(int argc, char *argv[])
44854487pgStatRunningInCollector = true;
44864488pgStatDBHash = pgstat_read_statsfiles (InvalidOid , true, true);
44874489
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+
44884496/*
44894497 * Loop to process messages until we get SIGQUIT or detect ungraceful
44904498 * death of our parent postmaster.
@@ -4672,10 +4680,7 @@ PgstatCollectorMain(int argc, char *argv[])
46724680
46734681/* Sleep until there's something to do */
46744682#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 );
46794684#else
46804685
46814686/*
@@ -4688,18 +4693,15 @@ PgstatCollectorMain(int argc, char *argv[])
46884693 * to not provoke "using stale statistics" complaints from
46894694 * backend_read_statsfile.
46904695 */
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 );
46964698#endif
46974699
46984700/*
46994701 * Emergency bailout if postmaster has died. This is to avoid the
47004702 * necessity for manual cleanup of all postmaster children.
47014703 */
4702- if (wr & WL_POSTMASTER_DEATH )
4704+ if (wr == 1 && event . events == WL_POSTMASTER_DEATH )
47034705break ;
47044706}/* end of outer loop */
47054707
@@ -4708,6 +4710,8 @@ PgstatCollectorMain(int argc, char *argv[])
47084710 */
47094711pgstat_write_statsfiles (true, true);
47104712
4713+ FreeWaitEventSet (wes );
4714+
47114715exit (0 );
47124716}
47134717