The following changes are done:
- Addition of WaitEventBufferPin and WaitEventExtension, that hold a
list of wait events related to each category.
- Addition of two functions that encapsulate the list of wait events for
each category.
- Rename BUFFER_PIN to BUFFERPIN (only this wait event class used an
underscore, requiring a specific rule in the automation script).
These changes make a bit easier the automatic generation of all the code
and documentation related to wait events, as all the wait event
categories are now controlled by consistent structures and functions.
Author: Bertrand Drouvot
Discussion: https://postgr.es/m/
c6f35117-4b20-4c78-1df5-
d3056010dcf5@gmail.com
Discussion: https://postgr.es/m/
77a86b3a-c4a8-5f5d-69b9-
d70bbf2e9b98@gmail.com
 
        dblink_connstr_check(connstr);
 
        /* OK to make connection */
-       conn = libpqsrv_connect(connstr, PG_WAIT_EXTENSION);
+       conn = libpqsrv_connect(connstr, WAIT_EVENT_EXTENSION);
 
        if (PQstatus(conn) == CONNECTION_BAD)
        {
    dblink_connstr_check(connstr);
 
    /* OK to make connection */
-   conn = libpqsrv_connect(connstr, PG_WAIT_EXTENSION);
+   conn = libpqsrv_connect(connstr, WAIT_EVENT_EXTENSION);
 
    if (PQstatus(conn) == CONNECTION_BAD)
    {
 
            (void) WaitLatch(MyLatch,
                             WL_LATCH_SET | WL_EXIT_ON_PM_DEATH,
                             -1L,
-                            PG_WAIT_EXTENSION);
+                            WAIT_EVENT_EXTENSION);
        }
        else
        {
            (void) WaitLatch(MyLatch,
                             WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
                             delay_in_ms,
-                            PG_WAIT_EXTENSION);
+                            WAIT_EVENT_EXTENSION);
        }
 
        /* Reset the latch, loop. */
 
        /* OK to make connection */
        conn = libpqsrv_connect_params(keywords, values,
                                       false,   /* expand_dbname */
-                                      PG_WAIT_EXTENSION);
+                                      WAIT_EVENT_EXTENSION);
 
        if (!conn || PQstatus(conn) != CONNECTION_OK)
            ereport(ERROR,
                                       WL_LATCH_SET | WL_SOCKET_READABLE |
                                       WL_EXIT_ON_PM_DEATH,
                                       PQsocket(conn),
-                                      -1L, PG_WAIT_EXTENSION);
+                                      -1L, WAIT_EVENT_EXTENSION);
                ResetLatch(MyLatch);
 
                CHECK_FOR_INTERRUPTS();
                                       WL_LATCH_SET | WL_SOCKET_READABLE |
                                       WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
                                       PQsocket(conn),
-                                      cur_timeout, PG_WAIT_EXTENSION);
+                                      cur_timeout, WAIT_EVENT_EXTENSION);
                ResetLatch(MyLatch);
 
                CHECK_FOR_INTERRUPTS();
 
            SetStartupBufferPinWaitBufId(-1);
        }
        else
-           ProcWaitForSignal(PG_WAIT_BUFFER_PIN);
+           ProcWaitForSignal(WAIT_EVENT_BUFFER_PIN);
 
        /*
         * Remove flag marking us as waiter. Normally this will not be set
 
     * SIGHUP signal handler, etc cannot do that because it uses the different
     * latch from that ProcWaitForSignal() waits on.
     */
-   ProcWaitForSignal(PG_WAIT_BUFFER_PIN);
+   ProcWaitForSignal(WAIT_EVENT_BUFFER_PIN);
 
    if (got_standby_delay_timeout)
        SendRecoveryConflictWithBufferPin(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
 
 
 
 static const char *pgstat_get_wait_activity(WaitEventActivity w);
+static const char *pgstat_get_wait_bufferpin(WaitEventBufferPin w);
 static const char *pgstat_get_wait_client(WaitEventClient w);
+static const char *pgstat_get_wait_extension(WaitEventExtension w);
 static const char *pgstat_get_wait_ipc(WaitEventIPC w);
 static const char *pgstat_get_wait_timeout(WaitEventTimeout w);
 static const char *pgstat_get_wait_io(WaitEventIO w);
        case PG_WAIT_LOCK:
            event_type = "Lock";
            break;
-       case PG_WAIT_BUFFER_PIN:
+       case PG_WAIT_BUFFERPIN:
            event_type = "BufferPin";
            break;
        case PG_WAIT_ACTIVITY:
        case PG_WAIT_LOCK:
            event_name = GetLockNameFromTagType(eventId);
            break;
-       case PG_WAIT_BUFFER_PIN:
-           event_name = "BufferPin";
-           break;
+       case PG_WAIT_BUFFERPIN:
+           {
+               WaitEventBufferPin w = (WaitEventBufferPin) wait_event_info;
+
+               event_name = pgstat_get_wait_bufferpin(w);
+               break;
+           }
        case PG_WAIT_ACTIVITY:
            {
                WaitEventActivity w = (WaitEventActivity) wait_event_info;
                break;
            }
        case PG_WAIT_EXTENSION:
-           event_name = "Extension";
-           break;
+           {
+               WaitEventExtension w = (WaitEventExtension) wait_event_info;
+
+               event_name = pgstat_get_wait_extension(w);
+               break;
+           }
        case PG_WAIT_IPC:
            {
                WaitEventIPC w = (WaitEventIPC) wait_event_info;
    return event_name;
 }
 
+/* ----------
+ * pgstat_get_wait_bufferpin() -
+ *
+ * Convert WaitEventBufferPin to string.
+ * ----------
+ */
+static const char *
+pgstat_get_wait_bufferpin(WaitEventBufferPin w)
+{
+   const char *event_name = "unknown wait event";
+
+   switch (w)
+   {
+       case WAIT_EVENT_BUFFER_PIN:
+           event_name = "BufferPin";
+           break;
+           /* no default case, so that compiler will warn */
+   }
+
+   return event_name;
+}
+
 /* ----------
  * pgstat_get_wait_client() -
  *
    return event_name;
 }
 
+/* ----------
+ * pgstat_get_wait_extension() -
+ *
+ * Convert WaitEventExtension to string.
+ * ----------
+ */
+static const char *
+pgstat_get_wait_extension(WaitEventExtension w)
+{
+   const char *event_name = "unknown wait event";
+
+   switch (w)
+   {
+       case WAIT_EVENT_EXTENSION:
+           event_name = "Extension";
+           break;
+           /* no default case, so that compiler will warn */
+   }
+
+   return event_name;
+}
+
 /* ----------
  * pgstat_get_wait_ipc() -
  *
 
  */
 #define PG_WAIT_LWLOCK             0x01000000U
 #define PG_WAIT_LOCK               0x03000000U
-#define PG_WAIT_BUFFER_PIN         0x04000000U
+#define PG_WAIT_BUFFERPIN          0x04000000U
 #define PG_WAIT_ACTIVITY           0x05000000U
 #define PG_WAIT_CLIENT             0x06000000U
 #define PG_WAIT_EXTENSION          0x07000000U
    WAIT_EVENT_WAL_WRITER_MAIN
 } WaitEventActivity;
 
+/* ----------
+ * Wait Events - BUFFERPIN
+ * ----------
+ */
+typedef enum
+{
+   WAIT_EVENT_BUFFER_PIN = PG_WAIT_BUFFERPIN
+} WaitEventBufferPin;
+
 /* ----------
  * Wait Events - Client
  *
    WAIT_EVENT_WAL_SENDER_WRITE_DATA,
 } WaitEventClient;
 
+/* ----------
+ * Wait Events - EXTENSION
+ * ----------
+ */
+typedef enum
+{
+   WAIT_EVENT_EXTENSION = PG_WAIT_EXTENSION
+} WaitEventExtension;
+
 /* ----------
  * Wait Events - IPC
  *
 
 
        /* Wait to be signaled. */
        (void) WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, 0,
-                        PG_WAIT_EXTENSION);
+                        WAIT_EVENT_EXTENSION);
 
        /* Reset the latch so we don't spin. */
        ResetLatch(MyLatch);
 
             * for us to do.
             */
            (void) WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, 0,
-                            PG_WAIT_EXTENSION);
+                            WAIT_EVENT_EXTENSION);
            ResetLatch(MyLatch);
            CHECK_FOR_INTERRUPTS();
        }
 
        (void) WaitLatch(MyLatch,
                         WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
                         worker_spi_naptime * 1000L,
-                        PG_WAIT_EXTENSION);
+                        WAIT_EVENT_EXTENSION);
        ResetLatch(MyLatch);
 
        CHECK_FOR_INTERRUPTS();
 
 WSAPROTOCOL_INFO
 WaitEvent
 WaitEventActivity
+WaitEventBufferPin
 WaitEventClient
+WaitEventExtension
 WaitEventIO
 WaitEventIPC
 WaitEventSet