summaryrefslogtreecommitdiff
path: root/src/backend/postmaster/postmaster.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2012-10-16 17:36:30 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2012-10-17 11:31:20 -0300
commita66ee69add6e129c7674a59f8c3ba010ed4c9386 (patch)
tree8e3b1f182d2b302904b7d6e32563da03e5c6aa61 /src/backend/postmaster/postmaster.c
parentf862a326efa3087440bc86cbfe58ea11c977068a (diff)
downloadpostgresql-a66ee69add6e129c7674a59f8c3ba010ed4c9386.tar.gz
Embedded list interface
Provide a common implementation of embedded singly-linked and doubly-linked lists. "Embedded" in the sense that the nodes' next/previous pointers exist within some larger struct; this design choice reduces memory allocation overhead. Most of the implementation uses inlineable functions (where supported), for performance. Some existing uses of both types of lists have been converted to the new code, for demonstration purposes. Other uses can (and probably will) be converted in the future. Since dllist.c is unused after this conversion, it has been removed. Author: Andres Freund Some tweaks by me Reviewed by Tom Lane, Peter Geoghegan
Diffstat (limited to 'src/backend/postmaster/postmaster.c')
-rw-r--r--src/backend/postmaster/postmaster.c57
1 files changed, 25 insertions, 32 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index dfe40492d2..c8a80f038c 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -95,7 +95,7 @@
#include "access/xlog.h"
#include "bootstrap/bootstrap.h"
#include "catalog/pg_control.h"
-#include "lib/dllist.h"
+#include "lib/ilist.h"
#include "libpq/auth.h"
#include "libpq/ip.h"
#include "libpq/libpq.h"
@@ -146,10 +146,10 @@ typedef struct bkend
int child_slot; /* PMChildSlot for this backend, if any */
bool is_autovacuum; /* is it an autovacuum process? */
bool dead_end; /* is it going to send an error and quit? */
- Dlelem elem; /* list link in BackendList */
+ dlist_node elem; /* list link in BackendList */
} Backend;
-static Dllist *BackendList;
+static dlist_head BackendList = DLIST_STATIC_INIT(BackendList);
#ifdef EXEC_BACKEND
static Backend *ShmemBackendArray;
@@ -1028,11 +1028,6 @@ PostmasterMain(int argc, char *argv[])
set_stack_base();
/*
- * Initialize the list of active backends.
- */
- BackendList = DLNewList();
-
- /*
* Initialize pipe (or process handle on Windows) that allows children to
* wake up from sleep on postmaster death.
*/
@@ -1872,7 +1867,7 @@ processCancelRequest(Port *port, void *pkt)
Backend *bp;
#ifndef EXEC_BACKEND
- Dlelem *curr;
+ dlist_iter iter;
#else
int i;
#endif
@@ -1886,9 +1881,9 @@ processCancelRequest(Port *port, void *pkt)
* duplicate array in shared memory.
*/
#ifndef EXEC_BACKEND
- for (curr = DLGetHead(BackendList); curr; curr = DLGetSucc(curr))
+ dlist_foreach(iter, &BackendList)
{
- bp = (Backend *) DLE_VAL(curr);
+ bp = dlist_container(Backend, elem, iter.cur);
#else
for (i = MaxLivePostmasterChildren() - 1; i >= 0; i--)
{
@@ -2648,7 +2643,7 @@ static void
CleanupBackend(int pid,
int exitstatus) /* child's exit status. */
{
- Dlelem *curr;
+ dlist_mutable_iter iter;
LogChildExit(DEBUG2, _("server process"), pid, exitstatus);
@@ -2680,9 +2675,9 @@ CleanupBackend(int pid,
return;
}
- for (curr = DLGetHead(BackendList); curr; curr = DLGetSucc(curr))
+ dlist_foreach_modify(iter, &BackendList)
{
- Backend *bp = (Backend *) DLE_VAL(curr);
+ Backend *bp = dlist_container(Backend, elem, iter.cur);
if (bp->pid == pid)
{
@@ -2701,7 +2696,7 @@ CleanupBackend(int pid,
ShmemBackendArrayRemove(bp);
#endif
}
- DLRemove(curr);
+ dlist_delete(&BackendList, iter.cur);
free(bp);
break;
}
@@ -2718,8 +2713,7 @@ CleanupBackend(int pid,
static void
HandleChildCrash(int pid, int exitstatus, const char *procname)
{
- Dlelem *curr,
- *next;
+ dlist_mutable_iter iter;
Backend *bp;
/*
@@ -2734,10 +2728,10 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
}
/* Process regular backends */
- for (curr = DLGetHead(BackendList); curr; curr = next)
+ dlist_foreach_modify(iter, &BackendList)
{
- next = DLGetSucc(curr);
- bp = (Backend *) DLE_VAL(curr);
+ bp = dlist_container(Backend, elem, iter.cur);
+
if (bp->pid == pid)
{
/*
@@ -2750,7 +2744,7 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
ShmemBackendArrayRemove(bp);
#endif
}
- DLRemove(curr);
+ dlist_delete(&BackendList, iter.cur);
free(bp);
/* Keep looping so we can signal remaining backends */
}
@@ -3113,7 +3107,7 @@ PostmasterStateMachine(void)
* normal state transition leading up to PM_WAIT_DEAD_END, or during
* FatalError processing.
*/
- if (DLGetHead(BackendList) == NULL &&
+ if (dlist_is_empty(&BackendList) &&
PgArchPID == 0 && PgStatPID == 0)
{
/* These other guys should be dead already */
@@ -3239,12 +3233,12 @@ signal_child(pid_t pid, int signal)
static bool
SignalSomeChildren(int signal, int target)
{
- Dlelem *curr;
+ dlist_iter iter;
bool signaled = false;
- for (curr = DLGetHead(BackendList); curr; curr = DLGetSucc(curr))
+ dlist_foreach(iter, &BackendList)
{
- Backend *bp = (Backend *) DLE_VAL(curr);
+ Backend *bp = dlist_container(Backend, elem, iter.cur);
if (bp->dead_end)
continue;
@@ -3382,8 +3376,8 @@ BackendStartup(Port *port)
*/
bn->pid = pid;
bn->is_autovacuum = false;
- DLInitElem(&bn->elem, bn);
- DLAddHead(BackendList, &bn->elem);
+ dlist_push_head(&BackendList, &bn->elem);
+
#ifdef EXEC_BACKEND
if (!bn->dead_end)
ShmemBackendArrayAdd(bn);
@@ -4491,12 +4485,12 @@ PostmasterRandom(void)
static int
CountChildren(int target)
{
- Dlelem *curr;
+ dlist_iter iter;
int cnt = 0;
- for (curr = DLGetHead(BackendList); curr; curr = DLGetSucc(curr))
+ dlist_foreach(iter, &BackendList)
{
- Backend *bp = (Backend *) DLE_VAL(curr);
+ Backend *bp = dlist_container(Backend, elem, iter.cur);
if (bp->dead_end)
continue;
@@ -4675,8 +4669,7 @@ StartAutovacuumWorker(void)
if (bn->pid > 0)
{
bn->is_autovacuum = true;
- DLInitElem(&bn->elem, bn);
- DLAddHead(BackendList, &bn->elem);
+ dlist_push_head(&BackendList, &bn->elem);
#ifdef EXEC_BACKEND
ShmemBackendArrayAdd(bn);
#endif