2 * Wireshark Memory Manager Doubly-Linked List
3 * Copyright 2012, Evan Huus <eapache@gmail.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "wmem_core.h"
30 #include "wmem_list.h"
32 struct _wmem_list_frame_t
{
33 struct _wmem_list_frame_t
*next
, *prev
;
39 wmem_list_frame_t
*head
, *tail
;
40 wmem_allocator_t
*allocator
;
44 wmem_list_count(const wmem_list_t
*list
)
50 wmem_list_head(const wmem_list_t
*list
)
56 wmem_list_tail(const wmem_list_t
*list
)
62 wmem_list_frame_next(const wmem_list_frame_t
*frame
)
68 wmem_list_frame_prev(const wmem_list_frame_t
*frame
)
74 wmem_list_frame_data(const wmem_list_frame_t
*frame
)
80 wmem_list_remove(wmem_list_t
*list
, void *data
)
82 wmem_list_frame_t
*frame
;
86 while (frame
&& frame
->data
!= data
) {
94 wmem_list_remove_frame(list
, frame
);
98 wmem_list_remove_frame(wmem_list_t
*list
, wmem_list_frame_t
*frame
)
101 frame
->prev
->next
= frame
->next
;
104 list
->head
= frame
->next
;
108 frame
->next
->prev
= frame
->prev
;
111 list
->tail
= frame
->prev
;
115 wmem_free(list
->allocator
, frame
);
119 wmem_list_prepend(wmem_list_t
*list
, void *data
)
121 wmem_list_frame_t
*new_frame
;
123 new_frame
= wmem_new(list
->allocator
, wmem_list_frame_t
);
125 new_frame
->data
= data
;
126 new_frame
->next
= list
->head
;
127 new_frame
->prev
= NULL
;
130 list
->head
->prev
= new_frame
;
133 list
->tail
= new_frame
;
136 list
->head
= new_frame
;
141 wmem_list_append(wmem_list_t
*list
, void *data
)
143 wmem_list_frame_t
*new_frame
;
145 new_frame
= wmem_new(list
->allocator
, wmem_list_frame_t
);
146 new_frame
->data
= data
;
147 new_frame
->next
= NULL
;
148 new_frame
->prev
= list
->tail
;
151 list
->tail
->next
= new_frame
;
154 list
->head
= new_frame
;
157 list
->tail
= new_frame
;
162 wmem_list_new(wmem_allocator_t
*allocator
)
166 list
= wmem_new(allocator
, wmem_list_t
);
171 list
->allocator
= allocator
;
177 * Editor modelines - http://www.wireshark.org/tools/modelines.html
182 * indent-tabs-mode: nil
185 * vi: set shiftwidth=4 tabstop=8 expandtab:
186 * :indentSize=4:tabSize=8:noTabs=true: