X-Git-Url: http://git.lttng.org/?p=lttv.git;a=blobdiff_plain;f=lttv%2Flttv%2Fhook.c;h=62918cd5e0a321f67f638e995ec09497a5a9415e;hp=57dcb04979025e07a539b7b67a0c00f62b01a2ea;hb=7a4bdb546094fea3343bfc80e3744ea26a08dd22;hpb=1111bb0f69e3c01c9264b19cbc7d2a8a02eeb569 diff --git a/lttv/lttv/hook.c b/lttv/lttv/hook.c index 57dcb049..62918cd5 100644 --- a/lttv/lttv/hook.c +++ b/lttv/lttv/hook.c @@ -40,7 +40,7 @@ gint lttv_hooks_prio_compare(LttvHookClosure *a, LttvHookClosure *b) } -LttvHooks *lttv_hooks_new() +LttvHooks *lttv_hooks_new(void) { return g_array_new(FALSE, FALSE, sizeof(LttvHookClosure)); } @@ -393,130 +393,4 @@ gboolean lttv_hooks_call_check_merge(LttvHooks *h1, void *call_data1, } return FALSE; - -} - -/* Two pointer arrays : - * * one indexed by id for quick search : - * size : max id - * typically 4 bytes * 256 facilities * 10 events = 10kbytes - * * another array that keeps a list of used numbers (for later deletion) - * size : number of ids used. - */ - -LttvHooksById *lttv_hooks_by_id_new() -{ - LttvHooksById *h = g_new(LttvHooksById, 1); - h->index = g_ptr_array_sized_new(PREALLOC_EVENTS); - h->array = g_array_sized_new(FALSE, FALSE, sizeof(guint), PREALLOC_EVENTS); - return h; -} - - -void lttv_hooks_by_id_destroy(LttvHooksById *h) -{ - guint i; - - for(i = 0 ; i < h->array->len ; i++) { - guint index = g_array_index(h->array, guint, i); - if(h->index->pdata[index] != NULL) { /* hook may have been removed */ - lttv_hooks_destroy(h->index->pdata[index]); - h->index->pdata[index] = NULL; /* Must be there in case of - multiple addition of the same index */ - } - } - g_ptr_array_free(h->index, TRUE); - g_array_free(h->array, TRUE); -} - -/* Optimised for searching an existing hook */ -LttvHooks *lttv_hooks_by_id_find(LttvHooksById *h, unsigned id) -{ - if(unlikely(h->index->len <= id)) g_ptr_array_set_size(h->index, id + 1); - if(unlikely(h->index->pdata[id] == NULL)) { - h->index->pdata[id] = lttv_hooks_new(); - g_array_append_val(h->array, id); - } - return h->index->pdata[id]; -} - - -unsigned lttv_hooks_by_id_max_id(LttvHooksById *h) -{ - return h->index->len; -} - -/* We don't bother removing the used slot array id : lttv_hooks_by_id_destroy is - * almost never called and is able to deal with used slot repetition. */ -void lttv_hooks_by_id_remove(LttvHooksById *h, unsigned id) -{ - if(likely(id < h->index->len && h->index->pdata[id] != NULL)) { - lttv_hooks_destroy((LttvHooks *)h->index->pdata[id]); - h->index->pdata[id] = NULL; - } -} - -void lttv_hooks_by_id_copy(LttvHooksById *dest, LttvHooksById *src) -{ - guint i; - - for(i = 0 ; i < src->array->len ; i++) { - guint index = g_array_index(src->array, guint, i); - LttvHooks *srch = lttv_hooks_by_id_find(src, index); - LttvHooks *desth = lttv_hooks_by_id_find(dest, index); - lttv_hooks_add_list(desth, srch); - } -} - -LttvHooksByIdChannelArray *lttv_hooks_by_id_channel_new(void) -{ - LttvHooksByIdChannelArray *h = g_new(LttvHooksByIdChannelArray, 1); - - h->array = g_array_new(FALSE, FALSE, sizeof(LttvHooksByIdChannel)); - return h; -} - -void lttv_hooks_by_id_channel_destroy(LttvHooksByIdChannelArray *h) -{ - LttvHooksByIdChannel *hid; - int i; - - for (i = 0; i < h->array->len; i++) { - hid = &g_array_index(h->array, LttvHooksByIdChannel, i); - lttv_hooks_by_id_destroy(hid->hooks_by_id); - } - g_array_free(h->array, TRUE); - g_free(h); -} - -static LttvHooksByIdChannel * -lttv_hooks_by_id_channel_find_channel(LttvHooksByIdChannelArray *h, - GQuark channel) -{ - LttvHooksByIdChannel *hid; - int i, found = 0; - - for (i = 0; i < h->array->len; i++) { - hid = &g_array_index(h->array, LttvHooksByIdChannel, i); - if (hid->channel == channel) { - found = 1; - break; - } - } - if (!found) { - g_array_set_size(h->array, h->array->len + 1); - hid = &g_array_index(h->array, LttvHooksByIdChannel, h->array->len - 1); - hid->channel = channel; - hid->hooks_by_id = lttv_hooks_by_id_new(); - } - return hid; -} - -/* get, or create if not found */ -LttvHooks *lttv_hooks_by_id_channel_find(LttvHooksByIdChannelArray *h, - GQuark channel, guint16 id) -{ - LttvHooksByIdChannel *hid; - hid = lttv_hooks_by_id_channel_find_channel(h, channel); - return lttv_hooks_by_id_find(hid->hooks_by_id, id); }