Commit a1e1ef4f authored by Alvaro Herrera's avatar Alvaro Herrera

Avoid a memory allocation in the backend startup code, to avoid having to check

whether it failed.  Modelled after catcache.c's usage of DlList, per suggestion
from Tom.
parent d85c6883
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.578 2009/05/02 22:02:37 tgl Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.579 2009/05/04 02:24:17 alvherre Exp $
* *
* NOTES * NOTES
* *
...@@ -143,6 +143,7 @@ typedef struct bkend ...@@ -143,6 +143,7 @@ typedef struct bkend
long cancel_key; /* cancel key for cancels for this backend */ long cancel_key; /* cancel key for cancels for this backend */
bool is_autovacuum; /* is it an autovacuum process? */ bool is_autovacuum; /* is it an autovacuum process? */
bool dead_end; /* is it going to send an error and quit? */ bool dead_end; /* is it going to send an error and quit? */
Dlelem elem; /* self pointer into BackendList */
} Backend; } Backend;
static Dllist *BackendList; static Dllist *BackendList;
...@@ -2459,7 +2460,6 @@ CleanupBackend(int pid, ...@@ -2459,7 +2460,6 @@ CleanupBackend(int pid,
#endif #endif
DLRemove(curr); DLRemove(curr);
free(bp); free(bp);
DLFreeElem(curr);
break; break;
} }
} }
...@@ -2506,7 +2506,6 @@ HandleChildCrash(int pid, int exitstatus, const char *procname) ...@@ -2506,7 +2506,6 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
#endif #endif
DLRemove(curr); DLRemove(curr);
free(bp); free(bp);
DLFreeElem(curr);
/* Keep looping so we can signal remaining backends */ /* Keep looping so we can signal remaining backends */
} }
else else
...@@ -3014,7 +3013,8 @@ BackendStartup(Port *port) ...@@ -3014,7 +3013,8 @@ BackendStartup(Port *port)
bn->is_autovacuum = false; bn->is_autovacuum = false;
bn->dead_end = (port->canAcceptConnections != CAC_OK && bn->dead_end = (port->canAcceptConnections != CAC_OK &&
port->canAcceptConnections != CAC_WAITBACKUP); port->canAcceptConnections != CAC_WAITBACKUP);
DLAddHead(BackendList, DLNewElem(bn)); DLInitElem(&bn->elem, bn);
DLAddHead(BackendList, &bn->elem);
#ifdef EXEC_BACKEND #ifdef EXEC_BACKEND
if (!bn->dead_end) if (!bn->dead_end)
ShmemBackendArrayAdd(bn); ShmemBackendArrayAdd(bn);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment