aboutsummaryrefslogtreecommitdiff
path: root/src/backend/lib/dllist.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-11-16 22:30:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-11-16 22:30:52 +0000
commita933ee38bbb8dffbc48a3363a94ff6f2a9f7964d (patch)
tree1c32737389b2530e7152dc2287161b36d9001e8c /src/backend/lib/dllist.c
parentcff23842a4c68301ddf34559c7af383bb5557054 (diff)
downloadpostgresql-a933ee38bbb8dffbc48a3363a94ff6f2a9f7964d.tar.gz
postgresql-a933ee38bbb8dffbc48a3363a94ff6f2a9f7964d.zip
Change SearchSysCache coding conventions so that a reference count is
maintained for each cache entry. A cache entry will not be freed until the matching ReleaseSysCache call has been executed. This eliminates worries about cache entries getting dropped while still in use. See my posting to pg-hackers of even date for more info.
Diffstat (limited to 'src/backend/lib/dllist.c')
-rw-r--r--src/backend/lib/dllist.c98
1 files changed, 32 insertions, 66 deletions
diff --git a/src/backend/lib/dllist.c b/src/backend/lib/dllist.c
index f38251934c4..175c02c3e7c 100644
--- a/src/backend/lib/dllist.c
+++ b/src/backend/lib/dllist.c
@@ -2,7 +2,6 @@
*
* dllist.c
* this is a simple doubly linked list implementation
- * replaces the old simplelists stuff
* the elements of the lists are void*
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
@@ -10,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/lib/dllist.c,v 1.18 2000/06/08 22:37:05 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/lib/dllist.c,v 1.19 2000/11/16 22:30:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -33,25 +32,33 @@ DLNewList(void)
{
Dllist *l;
- l = malloc(sizeof(Dllist));
+ l = (Dllist *) malloc(sizeof(Dllist));
l->dll_head = 0;
l->dll_tail = 0;
return l;
}
-/* free up a list and all the nodes in it --- but *not* whatever the nodes
+void
+DLInitList(Dllist *list)
+{
+ list->dll_head = 0;
+ list->dll_tail = 0;
+}
+
+/*
+ * free up a list and all the nodes in it --- but *not* whatever the nodes
* might point to!
*/
void
-DLFreeList(Dllist *l)
+DLFreeList(Dllist *list)
{
Dlelem *curr;
- while ((curr = DLRemHead(l)) != 0)
+ while ((curr = DLRemHead(list)) != 0)
free(curr);
- free(l);
+ free(list);
}
Dlelem *
@@ -59,7 +66,7 @@ DLNewElem(void *val)
{
Dlelem *e;
- e = malloc(sizeof(Dlelem));
+ e = (Dlelem *) malloc(sizeof(Dlelem));
e->dle_next = 0;
e->dle_prev = 0;
e->dle_val = val;
@@ -68,59 +75,18 @@ DLNewElem(void *val)
}
void
-DLFreeElem(Dlelem *e)
-{
- free(e);
-}
-
-Dlelem *
-DLGetHead(Dllist *l)
-{
- return l ? l->dll_head : 0;
-}
-
-/* get the value stored in the first element */
-#ifdef NOT_USED
-void *
-DLGetHeadVal(Dllist *l)
+DLInitElem(Dlelem *e, void *val)
{
- Dlelem *e = DLGetHead(l);
-
- return e ? e->dle_val : 0;
-}
-
-#endif
-
-Dlelem *
-DLGetTail(Dllist *l)
-{
- return l ? l->dll_tail : 0;
-}
-
-/* get the value stored in the last element */
-#ifdef NOT_USED
-void *
-DLGetTailVal(Dllist *l)
-{
- Dlelem *e = DLGetTail(l);
-
- return e ? e->dle_val : 0;
-}
-
-#endif
-
-#ifdef NOT_USED
-Dlelem *
-DLGetPred(Dlelem *e) /* get predecessor */
-{
- return e ? e->dle_prev : 0;
+ e->dle_next = 0;
+ e->dle_prev = 0;
+ e->dle_val = val;
+ e->dle_list = 0;
}
-#endif
-Dlelem *
-DLGetSucc(Dlelem *e) /* get successor */
+void
+DLFreeElem(Dlelem *e)
{
- return e ? e->dle_next : 0;
+ free(e);
}
void
@@ -131,16 +97,16 @@ DLRemove(Dlelem *e)
if (e->dle_prev)
e->dle_prev->dle_next = e->dle_next;
else
-/* must be the head element */
{
+ /* must be the head element */
Assert(e == l->dll_head);
l->dll_head = e->dle_next;
}
if (e->dle_next)
e->dle_next->dle_prev = e->dle_prev;
else
-/* must be the tail element */
{
+ /* must be the tail element */
Assert(e == l->dll_tail);
l->dll_tail = e->dle_prev;
}
@@ -194,12 +160,12 @@ DLRemHead(Dllist *l)
l->dll_head = result->dle_next;
- result->dle_next = 0;
- result->dle_list = 0;
-
if (result == l->dll_tail) /* if the head is also the tail */
l->dll_tail = 0;
+ result->dle_next = 0;
+ result->dle_list = 0;
+
return result;
}
@@ -217,12 +183,12 @@ DLRemTail(Dllist *l)
l->dll_tail = result->dle_prev;
- result->dle_prev = 0;
- result->dle_list = 0;
-
if (result == l->dll_head) /* if the tail is also the head */
l->dll_head = 0;
+ result->dle_prev = 0;
+ result->dle_list = 0;
+
return result;
}
@@ -241,8 +207,8 @@ DLMoveToFront(Dlelem *e)
if (e->dle_next)
e->dle_next->dle_prev = e->dle_prev;
else
-/* must be the tail element */
{
+ /* must be the tail element */
Assert(e == l->dll_tail);
l->dll_tail = e->dle_prev;
}