]> git.ipfire.org Git - thirdparty/squid.git/blob - src/dlink.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / dlink.cc
1 /*
2 * Copyright (C) 1996-2015 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_node use explicit alloc()/freeOne()
13 * XXX: convert to MEMPROXY_CLASS() API
14 */
15 #include "mem/Pool.h"
16
17 dlink_list ClientActiveRequests;
18
19 MemAllocator *dlink_node_pool = NULL;
20
21 dlink_node *
22 dlinkNodeNew()
23 {
24 if (dlink_node_pool == NULL)
25 dlink_node_pool = memPoolCreate("Dlink list nodes", sizeof(dlink_node));
26
27 /* where should we call delete dlink_node_pool;dlink_node_pool = NULL; */
28 return (dlink_node *)dlink_node_pool->alloc();
29 }
30
31 /** The node needs to be unlinked FIRST */
32 void
33 dlinkNodeDelete(dlink_node * m)
34 {
35 if (m == NULL)
36 return;
37
38 dlink_node_pool->freeOne(m);
39 }
40
41 void
42 dlinkAdd(void *data, dlink_node * m, dlink_list * list)
43 {
44 m->data = data;
45 m->prev = NULL;
46 m->next = list->head;
47
48 if (list->head)
49 list->head->prev = m;
50
51 list->head = m;
52
53 if (list->tail == NULL)
54 list->tail = m;
55 }
56
57 void
58 dlinkAddAfter(void *data, dlink_node * m, dlink_node * n, dlink_list * list)
59 {
60 m->data = data;
61 m->prev = n;
62 m->next = n->next;
63
64 if (n->next)
65 n->next->prev = m;
66 else {
67 assert(list->tail == n);
68 list->tail = m;
69 }
70
71 n->next = m;
72 }
73
74 void
75 dlinkAddTail(void *data, dlink_node * m, dlink_list * list)
76 {
77 m->data = data;
78 m->next = NULL;
79 m->prev = list->tail;
80
81 if (list->tail)
82 list->tail->next = m;
83
84 list->tail = m;
85
86 if (list->head == NULL)
87 list->head = m;
88 }
89
90 void
91 dlinkDelete(dlink_node * m, dlink_list * list)
92 {
93 if (m->next)
94 m->next->prev = m->prev;
95
96 if (m->prev)
97 m->prev->next = m->next;
98
99 if (m == list->head)
100 list->head = m->next;
101
102 if (m == list->tail)
103 list->tail = m->prev;
104
105 m->next = m->prev = NULL;
106 }
107