2 * Wireshark Memory Manager User Callbacks
3 * Copyright 2012, Evan Huus <eapache@gmail.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "wmem_core.h"
13 #include "wmem_allocator.h"
15 #include "wmem_user_cb.h"
16 #include "wmem_user_cb_int.h"
18 typedef struct _wmem_user_cb_container_t
{
21 struct _wmem_user_cb_container_t
*next
;
23 } wmem_user_cb_container_t
;
26 wmem_call_callbacks(wmem_allocator_t
*allocator
, wmem_cb_event_t event
)
28 wmem_user_cb_container_t
**prev
, *cur
;
31 prev
= &(allocator
->callbacks
);
32 cur
= allocator
->callbacks
;
37 again
= cur
->cb(allocator
, event
, cur
->user_data
);
39 /* if the callback requested deregistration, or this is being triggered
40 * by the final destruction of the allocator, remove the callback */
41 if (! again
|| event
== WMEM_CB_DESTROY_EVENT
) {
54 wmem_register_callback(wmem_allocator_t
*allocator
,
55 wmem_user_cb_t callback
, void *user_data
)
57 wmem_user_cb_container_t
*container
;
58 static unsigned next_id
= 1;
60 container
= wmem_new(NULL
, wmem_user_cb_container_t
);
62 container
->cb
= callback
;
63 container
->user_data
= user_data
;
64 container
->next
= allocator
->callbacks
;
65 container
->id
= next_id
++;
67 allocator
->callbacks
= container
;
73 wmem_unregister_callback(wmem_allocator_t
*allocator
, unsigned id
)
75 wmem_user_cb_container_t
**prev
, *cur
;
77 prev
= &(allocator
->callbacks
);
78 cur
= allocator
->callbacks
;
94 * Editor modelines - https://www.wireshark.org/tools/modelines.html
99 * indent-tabs-mode: nil
102 * vi: set shiftwidth=4 tabstop=8 expandtab:
103 * :indentSize=4:tabSize=8:noTabs=true: