Commit dc5aeca1 authored by Tom Lane's avatar Tom Lane

Remove unnecessary "head" arguments from some dlist/slist functions.

dlist_delete, dlist_insert_after, dlist_insert_before, slist_insert_after
do not need access to the list header, and indeed insisting on that negates
one of the main advantages of a doubly-linked list.

In consequence, revert addition of "cache_bucket" field to CatCTup.
parent 8f8d7464
...@@ -580,7 +580,6 @@ AutoVacLauncherMain(int argc, char *argv[]) ...@@ -580,7 +580,6 @@ AutoVacLauncherMain(int argc, char *argv[])
struct timeval nap; struct timeval nap;
TimestampTz current_time = 0; TimestampTz current_time = 0;
bool can_launch; bool can_launch;
avl_dbase *avdb;
int rc; int rc;
/* /*
...@@ -725,7 +724,8 @@ AutoVacLauncherMain(int argc, char *argv[]) ...@@ -725,7 +724,8 @@ AutoVacLauncherMain(int argc, char *argv[])
worker->wi_tableoid = InvalidOid; worker->wi_tableoid = InvalidOid;
worker->wi_proc = NULL; worker->wi_proc = NULL;
worker->wi_launchtime = 0; worker->wi_launchtime = 0;
dlist_push_head(&AutoVacuumShmem->av_freeWorkers, &worker->wi_links); dlist_push_head(&AutoVacuumShmem->av_freeWorkers,
&worker->wi_links);
AutoVacuumShmem->av_startingWorker = NULL; AutoVacuumShmem->av_startingWorker = NULL;
elog(WARNING, "worker took too long to start; canceled"); elog(WARNING, "worker took too long to start; canceled");
} }
...@@ -760,6 +760,8 @@ AutoVacLauncherMain(int argc, char *argv[]) ...@@ -760,6 +760,8 @@ AutoVacLauncherMain(int argc, char *argv[])
* distant adl_next_worker first, we obtain our database from the * distant adl_next_worker first, we obtain our database from the
* tail of the list. * tail of the list.
*/ */
avl_dbase *avdb;
avdb = dlist_tail_element(avl_dbase, adl_node, &DatabaseList); avdb = dlist_tail_element(avl_dbase, adl_node, &DatabaseList);
/* /*
...@@ -790,8 +792,6 @@ AutoVacLauncherMain(int argc, char *argv[]) ...@@ -790,8 +792,6 @@ AutoVacLauncherMain(int argc, char *argv[])
static void static void
launcher_determine_sleep(bool canlaunch, bool recursing, struct timeval * nap) launcher_determine_sleep(bool canlaunch, bool recursing, struct timeval * nap)
{ {
avl_dbase *avdb;
/* /*
* We sleep until the next scheduled vacuum. We trust that when the * We sleep until the next scheduled vacuum. We trust that when the
* database list was built, care was taken so that no entries have times * database list was built, care was taken so that no entries have times
...@@ -807,6 +807,7 @@ launcher_determine_sleep(bool canlaunch, bool recursing, struct timeval * nap) ...@@ -807,6 +807,7 @@ launcher_determine_sleep(bool canlaunch, bool recursing, struct timeval * nap)
{ {
TimestampTz current_time = GetCurrentTimestamp(); TimestampTz current_time = GetCurrentTimestamp();
TimestampTz next_wakeup; TimestampTz next_wakeup;
avl_dbase *avdb;
long secs; long secs;
int usecs; int usecs;
...@@ -1677,7 +1678,7 @@ FreeWorkerInfo(int code, Datum arg) ...@@ -1677,7 +1678,7 @@ FreeWorkerInfo(int code, Datum arg)
*/ */
AutovacuumLauncherPid = AutoVacuumShmem->av_launcherpid; AutovacuumLauncherPid = AutoVacuumShmem->av_launcherpid;
dlist_delete(&AutoVacuumShmem->av_runningWorkers, &MyWorkerInfo->wi_links); dlist_delete(&MyWorkerInfo->wi_links);
MyWorkerInfo->wi_dboid = InvalidOid; MyWorkerInfo->wi_dboid = InvalidOid;
MyWorkerInfo->wi_tableoid = InvalidOid; MyWorkerInfo->wi_tableoid = InvalidOid;
MyWorkerInfo->wi_proc = NULL; MyWorkerInfo->wi_proc = NULL;
...@@ -1685,7 +1686,8 @@ FreeWorkerInfo(int code, Datum arg) ...@@ -1685,7 +1686,8 @@ FreeWorkerInfo(int code, Datum arg)
MyWorkerInfo->wi_cost_delay = 0; MyWorkerInfo->wi_cost_delay = 0;
MyWorkerInfo->wi_cost_limit = 0; MyWorkerInfo->wi_cost_limit = 0;
MyWorkerInfo->wi_cost_limit_base = 0; MyWorkerInfo->wi_cost_limit_base = 0;
dlist_push_head(&AutoVacuumShmem->av_freeWorkers, &MyWorkerInfo->wi_links); dlist_push_head(&AutoVacuumShmem->av_freeWorkers,
&MyWorkerInfo->wi_links);
/* not mine anymore */ /* not mine anymore */
MyWorkerInfo = NULL; MyWorkerInfo = NULL;
...@@ -2863,7 +2865,8 @@ AutoVacuumShmemInit(void) ...@@ -2863,7 +2865,8 @@ AutoVacuumShmemInit(void)
/* initialize the WorkerInfo free list */ /* initialize the WorkerInfo free list */
for (i = 0; i < autovacuum_max_workers; i++) for (i = 0; i < autovacuum_max_workers; i++)
dlist_push_head(&AutoVacuumShmem->av_freeWorkers, &worker[i].wi_links); dlist_push_head(&AutoVacuumShmem->av_freeWorkers,
&worker[i].wi_links);
} }
else else
Assert(found); Assert(found);
......
...@@ -2696,7 +2696,7 @@ CleanupBackend(int pid, ...@@ -2696,7 +2696,7 @@ CleanupBackend(int pid,
ShmemBackendArrayRemove(bp); ShmemBackendArrayRemove(bp);
#endif #endif
} }
dlist_delete(&BackendList, iter.cur); dlist_delete(iter.cur);
free(bp); free(bp);
break; break;
} }
...@@ -2744,7 +2744,7 @@ HandleChildCrash(int pid, int exitstatus, const char *procname) ...@@ -2744,7 +2744,7 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
ShmemBackendArrayRemove(bp); ShmemBackendArrayRemove(bp);
#endif #endif
} }
dlist_delete(&BackendList, iter.cur); dlist_delete(iter.cur);
free(bp); free(bp);
/* Keep looping so we can signal remaining backends */ /* Keep looping so we can signal remaining backends */
} }
......
...@@ -370,7 +370,7 @@ CatCacheRemoveCTup(CatCache *cache, CatCTup *ct) ...@@ -370,7 +370,7 @@ CatCacheRemoveCTup(CatCache *cache, CatCTup *ct)
return; /* nothing left to do */ return; /* nothing left to do */
} }
dlist_delete(ct->cache_bucket, &ct->cache_elem); dlist_delete(&ct->cache_elem);
/* free associated tuple data */ /* free associated tuple data */
if (ct->tuple.t_data != NULL) if (ct->tuple.t_data != NULL)
...@@ -413,7 +413,7 @@ CatCacheRemoveCList(CatCache *cache, CatCList *cl) ...@@ -413,7 +413,7 @@ CatCacheRemoveCList(CatCache *cache, CatCList *cl)
} }
/* delink from linked list */ /* delink from linked list */
dlist_delete(&cache->cc_lists, &cl->cache_elem); dlist_delete(&cl->cache_elem);
/* free associated tuple data */ /* free associated tuple data */
if (cl->tuple.t_data != NULL) if (cl->tuple.t_data != NULL)
...@@ -1664,15 +1664,13 @@ CatalogCacheCreateEntry(CatCache *cache, HeapTuple ntp, ...@@ -1664,15 +1664,13 @@ CatalogCacheCreateEntry(CatCache *cache, HeapTuple ntp,
*/ */
ct->ct_magic = CT_MAGIC; ct->ct_magic = CT_MAGIC;
ct->my_cache = cache; ct->my_cache = cache;
ct->cache_bucket = &cache->cc_bucket[hashIndex];
ct->c_list = NULL; ct->c_list = NULL;
ct->refcount = 0; /* for the moment */ ct->refcount = 0; /* for the moment */
ct->dead = false; ct->dead = false;
ct->negative = negative; ct->negative = negative;
ct->hash_value = hashValue; ct->hash_value = hashValue;
dlist_push_head(ct->cache_bucket, &ct->cache_elem); dlist_push_head(&cache->cc_bucket[hashIndex], &ct->cache_elem);
cache->cc_ntup++; cache->cc_ntup++;
CacheHdr->ch_ntup++; CacheHdr->ch_ntup++;
......
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
* continue; // don't touch this one * continue; // don't touch this one
* *
* // unlink the current table from the linked list * // unlink the current table from the linked list
* dlist_delete(&db->tables, miter.cur); * dlist_delete(miter.cur);
* // as these lists never manage memory, we can still access the table * // as these lists never manage memory, we can still access the table
* // after it's been unlinked * // after it's been unlinked
* drop_table(db, tbl); * drop_table(db, tbl);
...@@ -271,11 +271,9 @@ extern void dlist_init(dlist_head *head); ...@@ -271,11 +271,9 @@ extern void dlist_init(dlist_head *head);
extern bool dlist_is_empty(dlist_head *head); extern bool dlist_is_empty(dlist_head *head);
extern void dlist_push_head(dlist_head *head, dlist_node *node); extern void dlist_push_head(dlist_head *head, dlist_node *node);
extern void dlist_push_tail(dlist_head *head, dlist_node *node); extern void dlist_push_tail(dlist_head *head, dlist_node *node);
extern void dlist_insert_after(dlist_head *head, extern void dlist_insert_after(dlist_node *after, dlist_node *node);
dlist_node *after, dlist_node *node); extern void dlist_insert_before(dlist_node *before, dlist_node *node);
extern void dlist_insert_before(dlist_head *head, extern void dlist_delete(dlist_node *node);
dlist_node *before, dlist_node *node);
extern void dlist_delete(dlist_head *head, dlist_node *node);
extern dlist_node *dlist_pop_head_node(dlist_head *head); extern dlist_node *dlist_pop_head_node(dlist_head *head);
extern void dlist_move_head(dlist_head *head, dlist_node *node); extern void dlist_move_head(dlist_head *head, dlist_node *node);
extern bool dlist_has_next(dlist_head *head, dlist_node *node); extern bool dlist_has_next(dlist_head *head, dlist_node *node);
...@@ -352,50 +350,34 @@ dlist_push_tail(dlist_head *head, dlist_node *node) ...@@ -352,50 +350,34 @@ dlist_push_tail(dlist_head *head, dlist_node *node)
* Insert a node after another *in the same list* * Insert a node after another *in the same list*
*/ */
STATIC_IF_INLINE void STATIC_IF_INLINE void
dlist_insert_after(dlist_head *head, dlist_node *after, dlist_node *node) dlist_insert_after(dlist_node *after, dlist_node *node)
{ {
dlist_check(head);
/* XXX: assert 'after' is in 'head'? */
node->prev = after; node->prev = after;
node->next = after->next; node->next = after->next;
after->next = node; after->next = node;
node->next->prev = node; node->next->prev = node;
dlist_check(head);
} }
/* /*
* Insert a node before another *in the same list* * Insert a node before another *in the same list*
*/ */
STATIC_IF_INLINE void STATIC_IF_INLINE void
dlist_insert_before(dlist_head *head, dlist_node *before, dlist_node *node) dlist_insert_before(dlist_node *before, dlist_node *node)
{ {
dlist_check(head);
/* XXX: assert 'before' is in 'head'? */
node->prev = before->prev; node->prev = before->prev;
node->next = before; node->next = before;
before->prev = node; before->prev = node;
node->prev->next = node; node->prev->next = node;
dlist_check(head);
} }
/* /*
* Delete 'node' from list. * Delete 'node' from its list (it must be in one).
*
* It is not allowed to delete a 'node' which is is not in the list 'head'
*/ */
STATIC_IF_INLINE void STATIC_IF_INLINE void
dlist_delete(dlist_head *head, dlist_node *node) dlist_delete(dlist_node *node)
{ {
dlist_check(head);
node->prev->next = node->next; node->prev->next = node->next;
node->next->prev = node->prev; node->next->prev = node->prev;
dlist_check(head);
} }
/* /*
...@@ -408,7 +390,7 @@ dlist_pop_head_node(dlist_head *head) ...@@ -408,7 +390,7 @@ dlist_pop_head_node(dlist_head *head)
Assert(!dlist_is_empty(head)); Assert(!dlist_is_empty(head));
node = head->head.next; node = head->head.next;
dlist_delete(head, node); dlist_delete(node);
return node; return node;
} }
...@@ -425,7 +407,7 @@ dlist_move_head(dlist_head *head, dlist_node *node) ...@@ -425,7 +407,7 @@ dlist_move_head(dlist_head *head, dlist_node *node)
if (head->head.next == node) if (head->head.next == node)
return; return;
dlist_delete(head, node); dlist_delete(node);
dlist_push_head(head, node); dlist_push_head(head, node);
dlist_check(head); dlist_check(head);
...@@ -591,8 +573,7 @@ dlist_tail_node(dlist_head *head) ...@@ -591,8 +573,7 @@ dlist_tail_node(dlist_head *head)
extern void slist_init(slist_head *head); extern void slist_init(slist_head *head);
extern bool slist_is_empty(slist_head *head); extern bool slist_is_empty(slist_head *head);
extern void slist_push_head(slist_head *head, slist_node *node); extern void slist_push_head(slist_head *head, slist_node *node);
extern void slist_insert_after(slist_head *head, extern void slist_insert_after(slist_node *after, slist_node *node);
slist_node *after, slist_node *node);
extern slist_node *slist_pop_head_node(slist_head *head); extern slist_node *slist_pop_head_node(slist_head *head);
extern bool slist_has_next(slist_head *head, slist_node *node); extern bool slist_has_next(slist_head *head, slist_node *node);
extern slist_node *slist_next_node(slist_head *head, slist_node *node); extern slist_node *slist_next_node(slist_head *head, slist_node *node);
...@@ -640,12 +621,10 @@ slist_push_head(slist_head *head, slist_node *node) ...@@ -640,12 +621,10 @@ slist_push_head(slist_head *head, slist_node *node)
* Insert a node after another *in the same list* * Insert a node after another *in the same list*
*/ */
STATIC_IF_INLINE void STATIC_IF_INLINE void
slist_insert_after(slist_head *head, slist_node *after, slist_node *node) slist_insert_after(slist_node *after, slist_node *node)
{ {
node->next = after->next; node->next = after->next;
after->next = node; after->next = node;
slist_check(head);
} }
/* /*
......
...@@ -82,7 +82,6 @@ typedef struct catctup ...@@ -82,7 +82,6 @@ typedef struct catctup
* lookups. * lookups.
*/ */
dlist_node cache_elem; /* list member of per-bucket list */ dlist_node cache_elem; /* list member of per-bucket list */
dlist_head *cache_bucket; /* containing bucket dlist */
/* /*
* The tuple may also be a member of at most one CatCList. (If a single * The tuple may also be a member of at most one CatCList. (If a single
......
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