aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wmem/wmem_core.h
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2013-05-07 19:23:10 +0000
committerEvan Huus <eapache@gmail.com>2013-05-07 19:23:10 +0000
commit2e92c6dfdec952484ebe96ea1718467c2fa5de6b (patch)
tree021f78948c075de21a76e60d05672ad929b4e11e /epan/wmem/wmem_core.h
parent572d68a33bc1fadcd0ff7b0de8b718fb98fc259c (diff)
Add user callbacks to wmem. This feature is a generic way to transparently mimic
the behaviour emem has for seasonal trees, which is that the master tree structure is not actually seasonal - it is permanent. When the seasonal memory pool is cleared, the root node pointer in all of these permanent trees is set to NULL, and the pool takes care of actually freeing the nodes. Wmem can now mimic this by allocating the tree header struct in epan_scope(), allocating any node structs in file_scope(), and registering a callback on file_scope() that NULLs the pointer in the epan_scope() header. Yes, this is confusing, but it seemed simpler than adding manual callback registrations to every single dissector that currently uses seasonal trees. The callbacks may also be useful for other things that need cleanup (I'm thinking resource handles stored in wmem memory that need to be fclosed or what-have-you before they the handle is lost). As indicated by the number of caveats in README.wmem, the implementation probably needs a bit of work to make it safer/saner/more-useful. Thoughts (or patches!) in this direction are more than welcome. svn path=/trunk/; revision=49205
Diffstat (limited to 'epan/wmem/wmem_core.h')
-rw-r--r--epan/wmem/wmem_core.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/epan/wmem/wmem_core.h b/epan/wmem/wmem_core.h
index 4ce51baba9..83735a7095 100644
--- a/epan/wmem/wmem_core.h
+++ b/epan/wmem/wmem_core.h
@@ -33,15 +33,19 @@
extern "C" {
#endif /* __cplusplus */
+/* Allocator structure and typedef */
+struct _wmem_allocator_t;
+typedef struct _wmem_allocator_t wmem_allocator_t;
+
+/* Different types of allocators */
typedef enum _wmem_allocator_type_t {
WMEM_ALLOCATOR_SIMPLE,
WMEM_ALLOCATOR_BLOCK,
WMEM_ALLOCATOR_STRICT
} wmem_allocator_type_t;
-struct _wmem_allocator_t;
-
-typedef struct _wmem_allocator_t wmem_allocator_t;
+/* User callback type for registering cleanup routines */
+typedef void (*wmem_user_cb_t) (wmem_allocator_t *, void *);
WS_DLL_PUBLIC
void *
@@ -78,6 +82,11 @@ wmem_gc(wmem_allocator_t *allocator);
WS_DLL_PUBLIC
void
+wmem_register_cleanup_callback(wmem_allocator_t *allocator,
+ wmem_user_cb_t callback, void *user_data);
+
+WS_DLL_PUBLIC
+void
wmem_destroy_allocator(wmem_allocator_t *allocator);
WS_DLL_PUBLIC