Avoid a memory allocation in the backend startup code, to avoid having to check
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 4 May 2009 02:24:17 +0000 (02:24 +0000)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 4 May 2009 02:24:17 +0000 (02:24 +0000)
whether it failed.  Modelled after catcache.c's usage of DlList, per suggestion
from Tom.

src/backend/postmaster/postmaster.c

index d7c2b732b6e8a62344073a6cc99e5dd3e9d5b13c..c20c7d482f4e16d2533f21bf6b7d09d48bf17137 100644 (file)
@@ -143,6 +143,7 @@ typedef struct bkend
        long            cancel_key;             /* cancel key for cancels for this backend */
        bool            is_autovacuum;  /* is it an autovacuum process? */
        bool            dead_end;               /* is it going to send an error and quit? */
+       Dlelem          elem;                   /* self pointer into BackendList */
 } Backend;
 
 static Dllist *BackendList;
@@ -2459,7 +2460,6 @@ CleanupBackend(int pid,
 #endif
                        DLRemove(curr);
                        free(bp);
-                       DLFreeElem(curr);
                        break;
                }
        }
@@ -2506,7 +2506,6 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
 #endif
                        DLRemove(curr);
                        free(bp);
-                       DLFreeElem(curr);
                        /* Keep looping so we can signal remaining backends */
                }
                else
@@ -3014,7 +3013,8 @@ BackendStartup(Port *port)
        bn->is_autovacuum = false;
        bn->dead_end = (port->canAcceptConnections != CAC_OK &&
                                        port->canAcceptConnections != CAC_WAITBACKUP);
-       DLAddHead(BackendList, DLNewElem(bn));
+       DLInitElem(&bn->elem, bn);
+       DLAddHead(BackendList, &bn->elem);
 #ifdef EXEC_BACKEND
        if (!bn->dead_end)
                ShmemBackendArrayAdd(bn);