diff options
-rw-r--r-- | doc/README.wmem | 10 | ||||
-rw-r--r-- | epan/wmem/Makefile.common | 1 | ||||
-rw-r--r-- | epan/wmem/wmem.h | 1 | ||||
-rw-r--r-- | epan/wmem/wmem_queue.h | 81 | ||||
-rw-r--r-- | epan/wmem/wmem_stack.c | 6 | ||||
-rw-r--r-- | epan/wmem/wmem_stack.h | 4 | ||||
-rw-r--r-- | epan/wmem/wmem_test.c | 32 |
7 files changed, 124 insertions, 11 deletions
diff --git a/doc/README.wmem b/doc/README.wmem index e1fea5d409..b779cf4351 100644 --- a/doc/README.wmem +++ b/doc/README.wmem @@ -92,14 +92,20 @@ wmem_strbuf.h 2.2.3 Container Data Structures +wmem_array.h + - A growable array (AKA vector) implementation. + wmem_list.h - A doubly-linked list implementation. +wmem_queue.h + - A queue implementation (first-in, first-out). + wmem_stack.h - - A stack implementation (push, pop, etc). + - A stack implementation (last-in, first-out). wmem_tree.h - - A red-black tree implementation. + - A balanced binary tree (red-black tree) implementation. 2.2.4 Miscellanious Utilities diff --git a/epan/wmem/Makefile.common b/epan/wmem/Makefile.common index c86398aaf6..24f8530a1e 100644 --- a/epan/wmem/Makefile.common +++ b/epan/wmem/Makefile.common @@ -48,6 +48,7 @@ LIBWMEM_INCLUDES = \ wmem_allocator_strict.h \ wmem_list.h \ wmem_miscutl.h \ + wmem_queue.h \ wmem_scopes.h \ wmem_stack.h \ wmem_strbuf.h \ diff --git a/epan/wmem/wmem.h b/epan/wmem/wmem.h index b1c3e37079..9400fd3c96 100644 --- a/epan/wmem/wmem.h +++ b/epan/wmem/wmem.h @@ -30,6 +30,7 @@ #include "wmem_core.h" #include "wmem_list.h" #include "wmem_miscutl.h" +#include "wmem_queue.h" #include "wmem_scopes.h" #include "wmem_stack.h" #include "wmem_strbuf.h" diff --git a/epan/wmem/wmem_queue.h b/epan/wmem/wmem_queue.h new file mode 100644 index 0000000000..c79489402c --- /dev/null +++ b/epan/wmem/wmem_queue.h @@ -0,0 +1,81 @@ +/* wmem_queue.h + * Definitions for the Wireshark Memory Manager Queue + * Copyright 2013, Evan Huus <eapache@gmail.com> + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __WMEM_QUEUE_H__ +#define __WMEM_QUEUE_H__ + +#include <string.h> +#include <glib.h> + +#include "wmem_core.h" +#include "wmem_list.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** @addtogroup wmem + * @{ + * @defgroup wmem-stack Queue + * + * A queue implementation on top of wmem. + * + * @{ + */ + +/* Wmem queue is implemented as a dumb wrapper over Wmem list and stack */ +typedef wmem_list_t wmem_queue_t; + +#define wmem_queue_count(X) wmem_list_count(X) + +#define wmem_queue_peek(QUEUE) wmem_stack_peek(QUEUE) + +#define wmem_queue_pop(QUEUE) wmem_stack_pop(QUEUE) + +#define wmem_queue_push(QUEUE, DATA) wmem_list_append((QUEUE), (DATA)) + +#define wmem_queue_new(ALLOCATOR) wmem_list_new(ALLOCATOR) + +/** @} + * @} */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __WMEM_QUEUE_H__ */ + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/epan/wmem/wmem_stack.c b/epan/wmem/wmem_stack.c index cf124a2930..3d04a7f6d4 100644 --- a/epan/wmem/wmem_stack.c +++ b/epan/wmem/wmem_stack.c @@ -56,12 +56,6 @@ wmem_stack_pop(wmem_stack_t *stack) return data; } -void -wmem_stack_push(wmem_stack_t *stack, void *data) -{ - wmem_list_prepend(stack, data); -} - /* * Editor modelines - http://www.wireshark.org/tools/modelines.html * diff --git a/epan/wmem/wmem_stack.h b/epan/wmem/wmem_stack.h index 569ae9455a..e2435c9b96 100644 --- a/epan/wmem/wmem_stack.h +++ b/epan/wmem/wmem_stack.h @@ -58,9 +58,7 @@ WS_DLL_PUBLIC void * wmem_stack_pop(wmem_stack_t *stack); -WS_DLL_PUBLIC -void -wmem_stack_push(wmem_stack_t *stack, void *data); +#define wmem_stack_push(STACK, DATA) wmem_list_prepend((STACK), (DATA)) #define wmem_stack_new(ALLOCATOR) wmem_list_new(ALLOCATOR) diff --git a/epan/wmem/wmem_test.c b/epan/wmem/wmem_test.c index 42abba0d37..c4dec8bc98 100644 --- a/epan/wmem/wmem_test.c +++ b/epan/wmem/wmem_test.c @@ -601,6 +601,37 @@ wmem_test_list(void) } static void +wmem_test_queue(void) +{ + wmem_allocator_t *allocator; + wmem_queue_t *queue; + unsigned int i; + + allocator = wmem_allocator_force_new(WMEM_ALLOCATOR_STRICT); + + queue = wmem_queue_new(allocator); + g_assert(queue); + g_assert(wmem_queue_count(queue) == 0); + + for (i=0; i<CONTAINER_ITERS; i++) { + wmem_queue_push(queue, GINT_TO_POINTER(i)); + + g_assert(wmem_queue_count(queue) == i+1); + g_assert(wmem_queue_peek(queue) == GINT_TO_POINTER(0)); + } + wmem_strict_check_canaries(allocator); + + for (i=0; i<CONTAINER_ITERS; i++) { + g_assert(wmem_queue_peek(queue) == GINT_TO_POINTER(i)); + g_assert(wmem_queue_pop(queue) == GINT_TO_POINTER(i)); + g_assert(wmem_queue_count(queue) == CONTAINER_ITERS-i-1); + } + g_assert(wmem_queue_count(queue) == 0); + + wmem_destroy_allocator(allocator); +} + +static void wmem_test_stack(void) { wmem_allocator_t *allocator; @@ -882,6 +913,7 @@ main(int argc, char **argv) g_test_add_func("/wmem/datastruct/array", wmem_test_array); g_test_add_func("/wmem/datastruct/list", wmem_test_list); + g_test_add_func("/wmem/datastruct/queue", wmem_test_queue); g_test_add_func("/wmem/datastruct/stack", wmem_test_stack); g_test_add_func("/wmem/datastruct/strbuf", wmem_test_strbuf); g_test_add_func("/wmem/datastruct/tree", wmem_test_tree); |