2 * Wireshark Memory Manager User Callbacks
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.
26 #include "wmem_core.h"
27 #include "wmem_allocator.h"
29 #include "wmem_user_cb.h"
30 #include "wmem_user_cb_int.h"
32 typedef struct _wmem_user_cb_container_t
{
35 struct _wmem_user_cb_container_t
*next
;
37 } wmem_user_cb_container_t
;
40 wmem_call_callbacks(wmem_allocator_t
*allocator
, wmem_cb_event_t event
)
42 wmem_user_cb_container_t
**prev
, *cur
;
45 prev
= &(allocator
->callbacks
);
46 cur
= allocator
->callbacks
;
51 again
= cur
->cb(allocator
, event
, cur
->user_data
);
53 /* if the callback requested deregistration, or this is being triggered
54 * by the final destruction of the allocator, remove the callback */
55 if (! again
|| event
== WMEM_CB_DESTROY_EVENT
) {
68 wmem_register_callback(wmem_allocator_t
*allocator
,
69 wmem_user_cb_t callback
, void *user_data
)
71 wmem_user_cb_container_t
*container
;
72 static guint next_id
= 0;
74 container
= wmem_new(NULL
, wmem_user_cb_container_t
);
76 container
->cb
= callback
;
77 container
->user_data
= user_data
;
78 container
->next
= allocator
->callbacks
;
79 container
->id
= next_id
++;
81 allocator
->callbacks
= container
;
87 wmem_unregister_callback(wmem_allocator_t
*allocator
, guint id
)
89 wmem_user_cb_container_t
**prev
, *cur
;
91 prev
= &(allocator
->callbacks
);
92 cur
= allocator
->callbacks
;
108 * Editor modelines - http://www.wireshark.org/tools/modelines.html
113 * indent-tabs-mode: nil
116 * vi: set shiftwidth=4 tabstop=8 expandtab:
117 * :indentSize=4:tabSize=8:noTabs=true: