]> git.ipfire.org Git - thirdparty/squid.git/blame - src/dlink.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / src / dlink.cc
CommitLineData
e1f7507e
AJ
1/*
2 * $Id$
3 */
f7f3304a 4#include "squid.h"
e1f7507e
AJ
5#include "dlink.h"
6
7/* dlink are Mem-pooled */
8#include "MemPool.h"
e1f7507e
AJ
9
10
11dlink_list ClientActiveRequests;
12
13MemAllocator *dlink_node_pool = NULL;
14
15dlink_node *
16dlinkNodeNew()
17{
18 if (dlink_node_pool == NULL)
19 dlink_node_pool = memPoolCreate("Dlink list nodes", sizeof(dlink_node));
20
21 /* where should we call delete dlink_node_pool;dlink_node_pool = NULL; */
22 return (dlink_node *)dlink_node_pool->alloc();
23}
24
25/** The node needs to be unlinked FIRST */
26void
27dlinkNodeDelete(dlink_node * m)
28{
29 if (m == NULL)
30 return;
31
dc47f531 32 dlink_node_pool->freeOne(m);
e1f7507e
AJ
33}
34
35void
36dlinkAdd(void *data, dlink_node * m, dlink_list * list)
37{
38 m->data = data;
39 m->prev = NULL;
40 m->next = list->head;
41
42 if (list->head)
43 list->head->prev = m;
44
45 list->head = m;
46
47 if (list->tail == NULL)
48 list->tail = m;
49}
50
51void
52dlinkAddAfter(void *data, dlink_node * m, dlink_node * n, dlink_list * list)
53{
54 m->data = data;
55 m->prev = n;
56 m->next = n->next;
57
58 if (n->next)
59 n->next->prev = m;
60 else {
61 assert(list->tail == n);
62 list->tail = m;
63 }
64
65 n->next = m;
66}
67
68void
69dlinkAddTail(void *data, dlink_node * m, dlink_list * list)
70{
71 m->data = data;
72 m->next = NULL;
73 m->prev = list->tail;
74
75 if (list->tail)
76 list->tail->next = m;
77
78 list->tail = m;
79
80 if (list->head == NULL)
81 list->head = m;
82}
83
84void
85dlinkDelete(dlink_node * m, dlink_list * list)
86{
87 if (m->next)
88 m->next->prev = m->prev;
89
90 if (m->prev)
91 m->prev->next = m->next;
92
93 if (m == list->head)
94 list->head = m->next;
95
96 if (m == list->tail)
97 list->tail = m->prev;
98
99 m->next = m->prev = NULL;
100}