From 1e50f3501a415068242b4cf1f28f82f7a39054f8 Mon Sep 17 00:00:00 2001
From: Pavel Borisov <pashkin.elfe@gmail.com>
Date: Wed, 23 Oct 2024 13:06:44 +0400
Subject: [PATCH v1] Refine comments on usage WL_POSTMASTER_DEATH

---
 src/backend/storage/ipc/latch.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/backend/storage/ipc/latch.c b/src/backend/storage/ipc/latch.c
index 608eb66abe..218607d7bd 100644
--- a/src/backend/storage/ipc/latch.c
+++ b/src/backend/storage/ipc/latch.c
@@ -554,8 +554,10 @@ WaitLatch(Latch *latch, int wakeEvents, long timeout,
  *
  * wakeEvents must include either WL_EXIT_ON_PM_DEATH for automatic exit
  * if the postmaster dies or WL_POSTMASTER_DEATH for a flag set in the
- * return value if the postmaster dies.  The latter is useful for rare cases
- * where some behavior other than immediate exit is needed.
+ * return value if the postmaster dies. The latter is useful for cases
+ * where some behavior other than immediate exit could be needed, though
+ * immediate exit is also allowed in processing WL_POSTMASTER_DEATH if
+ * no other behavior needed.
  *
  * NB: These days this is just a wrapper around the WaitEventSet API. When
  * using a latch very frequently, consider creating a longer living
@@ -693,7 +695,7 @@ SetLatch(Latch *latch)
 	}
 	else
 		kill(owner_pid, SIGURG);
-
+/:
 #else
 
 	/*
@@ -930,7 +932,7 @@ FreeWaitEventSetAfterFork(WaitEventSet *set)
 /* ---
  * Add an event to the set. Possible events are:
  * - WL_LATCH_SET: Wait for the latch to be set
- * - WL_POSTMASTER_DEATH: Wait for postmaster to die
+ * - WL_POSTMASTER_DEATH: Wait for postmaster to die or finish immediately
  * - WL_SOCKET_READABLE: Wait for socket to become readable,
  *	 can be combined in one event with other WL_SOCKET_* events
  * - WL_SOCKET_WRITEABLE: Wait for socket to become writeable,
@@ -958,6 +960,10 @@ FreeWaitEventSetAfterFork(WaitEventSet *set)
  * The user_data pointer specified here will be set for the events returned
  * by WaitEventSetWait(), allowing to easily associate additional data with
  * events.
+ *
+ * Unlike WL_EXIT_ON_PM_DEATH that is only for immediate exit WL_POSTMASTER_DEATH
+ * allows the process to set a return values and wait for postmaster to die, but
+ * also allows exiting immediately if return value is not needed.
  */
 int
 AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch,
-- 
2.39.2 (Apple Git-143)

