X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fgraph%2Fnotification%2Finactivity.c;h=becf17e017e0e124730b640fc84270f6c3746982;hb=56e18c4ce186892c36d7f2cb5078087425e60134;hp=181625db16c880509a324e2315f30c09c6a86e86;hpb=f6ccaed94e575af57fe6bf38154771bee4871a2a;p=babeltrace.git diff --git a/lib/graph/notification/inactivity.c b/lib/graph/notification/inactivity.c index 181625db..becf17e0 100644 --- a/lib/graph/notification/inactivity.c +++ b/lib/graph/notification/inactivity.c @@ -25,12 +25,11 @@ #include #include -#include -#include -#include -#include +#include +#include #include #include +#include #include static @@ -40,37 +39,24 @@ void bt_notification_inactivity_destroy(struct bt_object *obj) (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); - 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_clock_class_priority_map *cc_prio_map) + struct bt_private_connection_private_notification_iterator *notif_iter, + struct bt_clock_class *default_clock_class) { struct bt_notification_inactivity *notification; struct bt_notification *ret_notif = NULL; - 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_LOGD_STR("Creating inactivity notification object."); notification = g_new0(struct bt_notification_inactivity, 1); if (!notification) { BT_LOGE_STR("Failed to allocate one inactivity notification."); @@ -78,107 +64,44 @@ struct bt_notification *bt_notification_inactivity_create( } bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_INACTIVITY, - bt_notification_inactivity_destroy); + bt_notification_inactivity_destroy, NULL); ret_notif = ¬ification->parent; - notification->clock_values = g_hash_table_new_full(g_direct_hash, - g_direct_equal, bt_put, bt_put); - 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; } - 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_LOGD("Created inactivity notification object: addr=%p", + ret_notif); goto end; error: BT_PUT(ret_notif); end: - bt_put(cc_prio_map); return ret_notif; } -extern struct bt_clock_class_priority_map * -bt_notification_inactivity_get_clock_class_priority_map( - struct bt_notification *notification) +int 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 bt_get(inactivity_notification->cc_prio_map); -} - -struct bt_clock_value *bt_notification_inactivity_get_clock_value( - struct bt_notification *notification, - struct bt_clock_class *clock_class) -{ - struct bt_notification_inactivity *inactivity_notification; - - 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 bt_get(g_hash_table_lookup( - inactivity_notification->clock_values, clock_class)); -} - -BT_ASSERT_PRE_FUNC -static inline bool cc_prio_map_contains_clock_class( - struct bt_clock_class_priority_map *cc_prio_map, - struct bt_clock_class *clock_class) -{ - int ret = 0; - uint64_t prio; - - ret = bt_clock_class_priority_map_get_clock_class_priority( - cc_prio_map, clock_class, &prio); - return ret == 0; + 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); + return 0; } -int bt_notification_inactivity_set_clock_value( - struct bt_notification *notification, - struct bt_clock_value *clock_value) +struct bt_clock_value *bt_notification_inactivity_borrow_default_clock_value( + 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_value, "Clock value"); - BT_ASSERT_PRE_HOT(notification, "notification", - ": +%!+n", notification); - BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, - BT_NOTIFICATION_TYPE_INACTIVITY); - inactivity_notification = container_of(notification, - struct bt_notification_inactivity, parent); - BT_ASSERT_PRE(cc_prio_map_contains_clock_class( - inactivity_notification->cc_prio_map, clock_value->clock_class), - "Clock value's class is not mapped to a priority within the scope of the inactivity notification: " - "notif-addr=%p, cc-prio-map-addr=%p, " - "clock-class-addr=%p, clock-class-name=\"%s\", " - "clock-value-addr=%p", - inactivity_notification, - inactivity_notification->cc_prio_map, - clock_value->clock_class, - bt_clock_class_get_name(clock_value->clock_class), clock_value); - g_hash_table_insert(inactivity_notification->clock_values, - clock_value->clock_class, bt_get(clock_value)); - BT_LOGV("Set inactivity notification's clock value: " - "notif-addr=%p, cc-prio-map-addr=%p, " - "clock-class-addr=%p, clock-class-name=\"%s\", " - "clock-value-addr=%p", - inactivity_notification, - inactivity_notification->cc_prio_map, - clock_value->clock_class, - bt_clock_class_get_name(clock_value->clock_class), clock_value); - return 0; + BT_ASSERT_PRE_NON_NULL(notif, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY); + return inactivity->default_cv; }