]> git.ipfire.org Git - thirdparty/squid.git/blob - src/dlink.cc
Merge from trunk rev.13584
[thirdparty/squid.git] / src / dlink.cc
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #include "squid.h"
10 #include "dlink.h"
11
12 /* dlink are Mem-pooled */
13 #include "MemPool.h"
14
15 dlink_list ClientActiveRequests;
16
17 MemAllocator *dlink_node_pool = NULL;
18
19 dlink_node *
20 dlinkNodeNew()
21 {
22 if (dlink_node_pool == NULL)
23 dlink_node_pool = memPoolCreate("Dlink list nodes", sizeof(dlink_node));
24
25 /* where should we call delete dlink_node_pool;dlink_node_pool = NULL; */
26 return (dlink_node *)dlink_node_pool->alloc();
27 }
28
29 /** The node needs to be unlinked FIRST */
30 void
31 dlinkNodeDelete(dlink_node * m)
32 {
33 if (m == NULL)
34 return;
35
36 dlink_node_pool->freeOne(m);
37 }
38
39 void
40 dlinkAdd(void *data, dlink_node * m, dlink_list * list)
41 {
42 m->data = data;
43 m->prev = NULL;
44 m->next = list->head;
45
46 if (list->head)
47 list->head->prev = m;
48
49 list->head = m;
50
51 if (list->tail == NULL)
52 list->tail = m;
53 }
54
55 void
56 dlinkAddAfter(void *data, dlink_node * m, dlink_node * n, dlink_list * list)
57 {
58 m->data = data;
59 m->prev = n;
60 m->next = n->next;
61
62 if (n->next)
63 n->next->prev = m;
64 else {
65 assert(list->tail == n);
66 list->tail = m;
67 }
68
69 n->next = m;
70 }
71
72 void
73 dlinkAddTail(void *data, dlink_node * m, dlink_list * list)
74 {
75 m->data = data;
76 m->next = NULL;
77 m->prev = list->tail;
78
79 if (list->tail)
80 list->tail->next = m;
81
82 list->tail = m;
83
84 if (list->head == NULL)
85 list->head = m;
86 }
87
88 void
89 dlinkDelete(dlink_node * m, dlink_list * list)
90 {
91 if (m->next)
92 m->next->prev = m->prev;
93
94 if (m->prev)
95 m->prev->next = m->next;
96
97 if (m == list->head)
98 list->head = m->next;
99
100 if (m == list->tail)
101 list->tail = m->prev;
102
103 m->next = m->prev = NULL;
104 }