diff options
author | Soren Sandmann <sandmann@redhat.com> | 2006-07-31 04:50:34 +0000 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@src.gnome.org> | 2006-07-31 04:50:34 +0000 |
commit | d43cdf3c149823784f28876b95b3d1440a391b62 (patch) | |
tree | 978a830ed3eef368208d127925b9b085c34ee73a /stackstash.c | |
parent | 5efd06051c427e9eaf5f1b1afa60a7b69cda44ef (diff) |
Add a destroy notifier to StackStash
2006-07-31 Soren Sandmann <sandmann@redhat.com>
* stackstash.[ch]: Add a destroy notifier to StackStash
* collector.c (collector_create_profile): Pass g_free as destroy
notifier.
* collector.c (collector_reset): Pass NULL as destroy notifier
* profile.c (profile_load): Pass g_free here.
* profile.c (struct Profile): Remove unused "Node" typedef
* collector.c (resolve_symbols): Free the array here.
* TODO: various updates.
Diffstat (limited to 'stackstash.c')
-rw-r--r-- | stackstash.c | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/stackstash.c b/stackstash.c index ba1a4cc..21e2f6b 100644 --- a/stackstash.c +++ b/stackstash.c @@ -21,9 +21,10 @@ struct StackStash { - StackNode *root; - GHashTable *nodes_by_data; - int ref_count; + int ref_count; + StackNode * root; + GHashTable * nodes_by_data; + GDestroyNotify destroy; }; static StackNode * @@ -40,23 +41,25 @@ stack_node_new (void) return node; } +/* "destroy", if non-NULL, is called once on every address */ static StackStash * -create_stack_stash (void) +create_stack_stash (GDestroyNotify destroy) { StackStash *stash = g_new (StackStash, 1); stash->root = NULL; stash->nodes_by_data = g_hash_table_new (g_direct_hash, g_direct_equal); stash->ref_count = 1; + stash->destroy = destroy; return stash; } /* Stach */ StackStash * -stack_stash_new (void) +stack_stash_new (GDestroyNotify destroy) { - return create_stack_stash(); + return create_stack_stash (destroy); } void @@ -79,7 +82,7 @@ decorate_node (StackStash *stash, } node->toplevel = toplevel; - + node->next = g_hash_table_lookup ( stash->nodes_by_data, node->address); g_hash_table_insert ( @@ -196,9 +199,26 @@ stack_node_free (StackNode *node) } static void +free_key (gpointer key, + gpointer value, + gpointer data) +{ + GDestroyNotify destroy = data; + + destroy (key); +} + +static void stack_stash_free (StackStash *stash) { stack_node_free (stash->root); + + if (stash->destroy) + { + g_hash_table_foreach (stash->nodes_by_data, free_key, + stash->destroy); + } + g_hash_table_destroy (stash->nodes_by_data); g_free (stash); @@ -277,9 +297,10 @@ build_hash_table (StackNode *node, } StackStash * -stack_stash_new_from_root (StackNode *root) +stack_stash_new_from_root (StackNode *root, + GDestroyNotify destroy) { - StackStash *stash = create_stack_stash(); + StackStash *stash = create_stack_stash (destroy); stash->root = root; |