X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fgraph%2Fnotification%2Finactivity.c;h=47d759d4d3aa33f7ef058841b8624c85d360cb70;hb=c8db321922f3730c70628a5e452baf8a046e70fd;hp=b6708d3b6ad5f4c74bbe11196449d05d636678cd;hpb=5c5632787fc9cafa602c89a28966bcfd01ec0204;p=babeltrace.git diff --git a/lib/graph/notification/inactivity.c b/lib/graph/notification/inactivity.c index b6708d3b..47d759d4 100644 --- a/lib/graph/notification/inactivity.c +++ b/lib/graph/notification/inactivity.c @@ -1,5 +1,5 @@ /* - * Copyright 2017 Philippe Proulx + * Copyright 2017-2018 Philippe Proulx * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,15 +23,15 @@ #define BT_LOG_TAG "NOTIF-INACTIVITY" #include +#include #include #include -#include -#include -#include -#include +#include +#include #include +#include +#include #include -#include static void bt_notification_inactivity_destroy(struct bt_object *obj) @@ -39,40 +39,29 @@ void bt_notification_inactivity_destroy(struct bt_object *obj) struct bt_notification_inactivity *notification = (struct bt_notification_inactivity *) obj; - BT_LOGD("Destroying inactivity notification: addr=%p", notification); - BT_LOGD_STR("Putting clock class priority map."); - bt_put(notification->cc_prio_map); + BT_LIB_LOGD("Destroying inactivity notification: %!+n", notification); - if (notification->clock_values) { - BT_LOGD_STR("Putting clock values."); - g_hash_table_destroy(notification->clock_values); + if (notification->default_cv) { + bt_clock_value_recycle(notification->default_cv); } g_free(notification); } struct bt_notification *bt_notification_inactivity_create( - struct bt_graph *graph, - struct bt_clock_class_priority_map *cc_prio_map) + struct bt_self_notification_iterator *self_notif_iter, + struct bt_clock_class *default_clock_class) { + struct bt_self_component_port_input_notification_iterator *notif_iter = + (void *) self_notif_iter; struct bt_notification_inactivity *notification; struct bt_notification *ret_notif = NULL; - uint64_t i; - if (cc_prio_map) { - /* Function's reference, released at the end */ - bt_get(cc_prio_map); - } else { - cc_prio_map = bt_clock_class_priority_map_create(); - if (!cc_prio_map) { - BT_LOGE_STR("Cannot create empty clock class priority map."); - goto error; - } - } - - BT_LOGD("Creating inactivity notification object: " - "cc-prio-map-addr=%p", - cc_prio_map); + BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); + BT_ASSERT_PRE_NON_NULL(default_clock_class, "Default clock class"); + BT_LIB_LOGD("Creating inactivity notification object: " + "%![iter-]+i, %![default-cc-]+K", notif_iter, + default_clock_class); notification = g_new0(struct bt_notification_inactivity, 1); if (!notification) { BT_LOGE_STR("Failed to allocate one inactivity notification."); @@ -82,71 +71,41 @@ struct bt_notification *bt_notification_inactivity_create( BT_NOTIFICATION_TYPE_INACTIVITY, bt_notification_inactivity_destroy, NULL); ret_notif = ¬ification->parent; - notification->clock_values = g_hash_table_new_full(g_direct_hash, - g_direct_equal, NULL, (GDestroyNotify) bt_clock_value_recycle); - if (!notification->clock_values) { - BT_LOGE_STR("Failed to allocate a GHashTable."); + notification->default_cv = bt_clock_value_create(default_clock_class); + if (!notification->default_cv) { goto error; } - for (i = 0; i < cc_prio_map->entries->len; i++) { - struct bt_clock_value *clock_value; - struct bt_clock_class *clock_class = - cc_prio_map->entries->pdata[i]; - - clock_value = bt_clock_value_create(clock_class); - if (!clock_value) { - BT_LIB_LOGE("Cannot create clock value from clock class: " - "%![cc-]+K", clock_class); - goto error; - } - - g_hash_table_insert(notification->clock_values, - clock_class, clock_value); - } - - notification->cc_prio_map = bt_get(cc_prio_map); - BT_LOGD_STR("Freezing inactivity notification's clock class priority map."); - bt_clock_class_priority_map_freeze(cc_prio_map); - BT_LOGD("Created inactivity notification object: " - "cc-prio-map-addr=%p, notif-addr=%p", - cc_prio_map, ret_notif); + BT_LIB_LOGD("Created inactivity notification object: %!+n", ret_notif); goto end; error: - BT_PUT(ret_notif); + BT_OBJECT_PUT_REF_AND_RESET(ret_notif); end: - bt_put(cc_prio_map); - return ret_notif; + return (void *) ret_notif; } -extern struct bt_clock_class_priority_map * -bt_notification_inactivity_borrow_clock_class_priority_map( - struct bt_notification *notification) +void bt_notification_inactivity_set_default_clock_value( + struct bt_notification *notif, uint64_t value_cycles) { - struct bt_notification_inactivity *inactivity_notification; - - BT_ASSERT_PRE_NON_NULL(notification, "Notification"); - BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, - BT_NOTIFICATION_TYPE_INACTIVITY); - inactivity_notification = container_of(notification, - struct bt_notification_inactivity, parent); - return inactivity_notification->cc_prio_map; + struct bt_notification_inactivity *inactivity = (void *) notif; + + BT_ASSERT_PRE_NON_NULL(notif, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY); + BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); + bt_clock_value_set_value_inline(inactivity->default_cv, value_cycles); + BT_LIB_LOGV("Set inactivity notification's default clock value: " + "%![notif-]+n, value=%" PRIu64, notif, value_cycles); } -struct bt_clock_value *bt_notification_inactivity_borrow_clock_value( - struct bt_notification *notification, - struct bt_clock_class *clock_class) +const struct bt_clock_value * +bt_notification_inactivity_borrow_default_clock_value_const( + const struct bt_notification *notif) { - struct bt_notification_inactivity *inactivity_notification; + struct bt_notification_inactivity *inactivity = (void *) notif; - BT_ASSERT_PRE_NON_NULL(notification, "Notification"); - BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); - BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, - BT_NOTIFICATION_TYPE_INACTIVITY); - inactivity_notification = container_of(notification, - struct bt_notification_inactivity, parent); - return g_hash_table_lookup( - inactivity_notification->clock_values, clock_class); + BT_ASSERT_PRE_NON_NULL(notif, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY); + return inactivity->default_cv; }