]> git.ipfire.org Git - thirdparty/squid.git/blame - src/dlink.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / dlink.cc
CommitLineData
bbc27441
AJ
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
f7f3304a 9#include "squid.h"
e1f7507e
AJ
10#include "dlink.h"
11
ed6e9fb9
AJ
12/* dlink_node use explicit alloc()/freeOne()
13 * XXX: convert to MEMPROXY_CLASS() API
14 */
15#include "mem/Pool.h"
e1f7507e 16
e1f7507e
AJ
17dlink_list ClientActiveRequests;
18
19MemAllocator *dlink_node_pool = NULL;
20
21dlink_node *
22dlinkNodeNew()
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 */
32void
33dlinkNodeDelete(dlink_node * m)
34{
35 if (m == NULL)
36 return;
37
dc47f531 38 dlink_node_pool->freeOne(m);
e1f7507e
AJ
39}
40
41void
42dlinkAdd(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
57void
58dlinkAddAfter(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
74void
75dlinkAddTail(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
90void
91dlinkDelete(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}
f53969cc 107