lib: message API: add fast default clock class accessors
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 19 Feb 2019 18:56:37 +0000 (13:56 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
This patch adds a few
bt_message_X_borrow_stream_class_default_clock_class() functions to
quickly get the default clock class of a message's stream class.

It is a library precondition that a message's stream class has a default
clock class in order to borrow its default clock snapshot. This is
because, sometimes, a default clock snapshot object exists even if it's
never used for pooling and allocation reasons. There's no conditional in
the clock snapshot borrowing functions for performance reasons, so you
can't rely on the clock snapshot output parameter being `NULL` or not.
The correct way to know whether or not there's a default clock snapshot
to check if the message's stream class has a default clock class, which
you can now do in a single call.

For example, before:

    const bt_message *event_msg = ...;
    const bt_event *event = bt_message_event_borrow_event_const(event_msg);
    const bt_packet *packet = bt_event_borrow_packet_const(event);
    const bt_stream *stream = bt_packet_borrow_stream_const(event);
    const bt_stream_class *stream_class =
        bt_stream_borrow_class_const(stream);
    const bt_clock_class *def_clock_class =
        bt_stream_class_borrow_default_clock_class_const(stream_class);

    if (def_clock_class) {
        /* safe to borrow message's default clock snapshot */
    }

Now:

    const bt_message *event_msg = ...;
    const bt_clock_class *def_clock_class =
        bt_message_event_borrow_stream_class_default_clock_class_const(
            event_msg);

    if (def_clock_class) {
        /* safe to borrow message's default clock snapshot */
    }

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
include/babeltrace/graph/message-discarded-events-const.h
include/babeltrace/graph/message-discarded-packets-const.h
include/babeltrace/graph/message-event-const.h
include/babeltrace/graph/message-packet-beginning-const.h
include/babeltrace/graph/message-packet-end-const.h
include/babeltrace/graph/message-stream-activity-beginning-const.h
include/babeltrace/graph/message-stream-activity-end-const.h
lib/graph/message/discarded-items.c
lib/graph/message/event.c
lib/graph/message/packet.c
lib/graph/message/stream-activity.c

index 221667f66cd5c93c0f287cf3336fc24c06f54d2d..68615526f254d30dded6d2c4901887d42737cd4a 100644 (file)
@@ -41,6 +41,10 @@ extern bt_clock_snapshot_state
 bt_message_discarded_events_borrow_default_end_clock_snapshot_const(
                const bt_message *msg, const bt_clock_snapshot **snapshot);
 
+extern const bt_clock_class *
+bt_message_discarded_events_borrow_stream_class_default_clock_class_const(
+               const bt_message *msg);
+
 extern const bt_stream *
 bt_message_discarded_events_borrow_stream_const(const bt_message *message);
 
index ab067d78a17b9ce755868b42ee0cc5d7ad4c5ff7..77d5d413dfcf2686e4bdf56b2b2f2285bb8c9c12 100644 (file)
@@ -41,6 +41,10 @@ extern bt_clock_snapshot_state
 bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
                const bt_message *msg, const bt_clock_snapshot **snapshot);
 
+extern const bt_clock_class *
+bt_message_discarded_packets_borrow_stream_class_default_clock_class_const(
+               const bt_message *msg);
+
 extern const bt_stream *
 bt_message_discarded_packets_borrow_stream_const(const bt_message *message);
 
index 3de48c485f713ab9cd60f97af8cee76ec1c58718..4c611925874a31255bff826696d4ab17ddfcf35c 100644 (file)
@@ -24,7 +24,7 @@
  * SOFTWARE.
  */
 
-/* For bt_message, bt_event */
+/* For bt_bool, bt_message, bt_event. bt_clock_class, bt_clock_snapshot */
 #include <babeltrace/types.h>
 
 /* For bt_clock_snapshot_state */
@@ -41,6 +41,10 @@ extern bt_clock_snapshot_state
 bt_message_event_borrow_default_clock_snapshot_const(
                const bt_message *msg, const bt_clock_snapshot **snapshot);
 
+extern const bt_clock_class *
+bt_message_event_borrow_stream_class_default_clock_class_const(
+               const bt_message *msg);
+
 #ifdef __cplusplus
 }
 #endif
index 49ebfcbf859751604a30498888c0353ec5dfe341..a7cc1348a5cadd56f18c0d7079c04be67a775823 100644 (file)
@@ -24,7 +24,7 @@
  * SOFTWARE.
  */
 
-/* For bt_message, bt_packet */
+/* For bt_message, bt_packet, bt_clock_snapshot, bt_clock_class */
 #include <babeltrace/types.h>
 
 /* For bt_clock_snapshot_state */
@@ -41,6 +41,10 @@ extern bt_clock_snapshot_state
 bt_message_packet_beginning_borrow_default_clock_snapshot_const(
                const bt_message *msg, const bt_clock_snapshot **snapshot);
 
+extern const bt_clock_class *
+bt_message_packet_beginning_borrow_stream_class_default_clock_class_const(
+               const bt_message *msg);
+
 #ifdef __cplusplus
 }
 #endif
index 44d18535fd40c7e1c644d765ae5a96756d17b8bd..3a48911e980389a515c7d78b6378a3bcbe823fcf 100644 (file)
@@ -24,7 +24,7 @@
  * SOFTWARE.
  */
 
-/* For bt_message, bt_packet */
+/* For bt_message, bt_packet, bt_clock_snapshot, bt_clock_class */
 #include <babeltrace/types.h>
 
 /* For bt_clock_snapshot_state */
@@ -41,6 +41,10 @@ extern bt_clock_snapshot_state
 bt_message_packet_end_borrow_default_clock_snapshot_const(
                const bt_message *msg, const bt_clock_snapshot **snapshot);
 
+extern const bt_clock_class *
+bt_message_packet_end_borrow_stream_class_default_clock_class_const(
+               const bt_message *msg);
+
 #ifdef __cplusplus
 }
 #endif
index 919b1185baa6bc73e97ad6b7e0b2ae1062820b4a..3e1d7a9dca2608d41684728b499c42293f2786c7 100644 (file)
@@ -23,7 +23,7 @@
  * SOFTWARE.
  */
 
-/* For bt_message, bt_clock_snapshot, bt_stream */
+/* For bt_message, bt_clock_snapshot, bt_stream, bt_clock_class */
 #include <babeltrace/types.h>
 
 /* For bt_message_stream_activity_clock_snapshot_state */
@@ -37,6 +37,10 @@ extern bt_message_stream_activity_clock_snapshot_state
 bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
                const bt_message *msg, const bt_clock_snapshot **snapshot);
 
+extern const bt_clock_class *
+bt_message_stream_activity_beginning_borrow_stream_class_default_clock_class_const(
+               const bt_message *msg);
+
 extern const bt_stream *
 bt_message_stream_activity_beginning_borrow_stream_const(
                const bt_message *message);
index d10540a222809baddbe588c543df4a35fb7735f4..4cf957b3fe84a7d5f6f28ed928ef1b3dd42e4971 100644 (file)
@@ -23,7 +23,7 @@
  * SOFTWARE.
  */
 
-/* For bt_message, bt_clock_snapshot, bt_stream */
+/* For bt_message, bt_clock_snapshot, bt_stream, bt_clock_class */
 #include <babeltrace/types.h>
 
 /* For bt_message_stream_activity_clock_snapshot_state */
@@ -37,6 +37,10 @@ extern bt_message_stream_activity_clock_snapshot_state
 bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
                const bt_message *msg, const bt_clock_snapshot **snapshot);
 
+extern const bt_clock_class *
+bt_message_stream_activity_end_borrow_stream_class_default_clock_class_const(
+               const bt_message *msg);
+
 extern const bt_stream *
 bt_message_stream_activity_end_borrow_stream_const(
                const bt_message *message);
index a4bc9e3b2f8b527302238f794e3b50ef9ea9f92f..cd40a3f3fa6a25a2b07922d439881949705e8e93 100644 (file)
@@ -344,3 +344,34 @@ enum bt_property_availability bt_message_discarded_packets_get_count(
        BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
        return get_discarded_items_message_count(message, count);
 }
+
+static inline
+const struct bt_clock_class *
+borrow_discarded_items_message_stream_class_default_clock_class(
+               const struct bt_message *msg)
+{
+       struct bt_message_discarded_items *disc_items_msg = (void *) msg;
+
+       BT_ASSERT(msg);
+       return disc_items_msg->stream->class->default_clock_class;
+}
+
+const struct bt_clock_class *
+bt_message_discarded_events_borrow_stream_class_default_clock_class_const(
+               const struct bt_message *msg)
+{
+       BT_ASSERT_PRE_NON_NULL(msg, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_EVENTS);
+       return borrow_discarded_items_message_stream_class_default_clock_class(
+               msg);
+}
+
+const struct bt_clock_class *
+bt_message_discarded_packets_borrow_stream_class_default_clock_class_const(
+               const struct bt_message *msg)
+{
+       BT_ASSERT_PRE_NON_NULL(msg, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
+       return borrow_discarded_items_message_stream_class_default_clock_class(
+               msg);
+}
index e79eb3de9d58702980780dd5e453bf626d528c8f..33e423e1ed1e6da34449df8b20da3cd5e4211420 100644 (file)
@@ -47,7 +47,7 @@ static inline bool event_class_has_trace(struct bt_event_class *event_class)
 {
        struct bt_stream_class *stream_class;
 
-       stream_class = bt_event_class_borrow_stream_class(event_class);
+       stream_class = bt_event_class_borrow_stream_class_inline(event_class);
        BT_ASSERT(stream_class);
        return bt_stream_class_borrow_trace_class(stream_class) != NULL;
 }
@@ -265,8 +265,7 @@ bt_message_event_borrow_default_clock_snapshot_const(
 
        BT_ASSERT_PRE_NON_NULL(msg, "Message");
        BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_EVENT);
-       BT_ASSERT(msg);
-       stream_class = bt_event_class_borrow_stream_class(
+       stream_class = bt_event_class_borrow_stream_class_inline(
                event_msg->event->class);
        BT_ASSERT(stream_class);
        BT_ASSERT_PRE(stream_class->default_clock_class,
@@ -276,3 +275,18 @@ bt_message_event_borrow_default_clock_snapshot_const(
        *snapshot = event_msg->default_cs;
        return BT_CLOCK_SNAPSHOT_STATE_KNOWN;
 }
+
+const bt_clock_class *
+bt_message_event_borrow_stream_class_default_clock_class_const(
+               const bt_message *msg)
+{
+       struct bt_message_event *event_msg = (void *) msg;
+       struct bt_stream_class *stream_class;
+
+       BT_ASSERT_PRE_NON_NULL(msg, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_EVENT);
+       stream_class = bt_event_class_borrow_stream_class_inline(
+               event_msg->event->class);
+       BT_ASSERT(stream_class);
+       return stream_class->default_clock_class;
+}
index a61999aedc16ec39354b697f3d8afcc6e9fac665..87c241e0e120c373ece2c4cd14be11906da84364 100644 (file)
@@ -323,3 +323,32 @@ bt_message_packet_end_borrow_default_clock_snapshot_const(
        return borrow_packet_message_default_clock_snapshot_const(
                msg, snapshot);
 }
+
+static inline
+const struct bt_clock_class *
+borrow_packet_message_stream_class_default_clock_class(
+               const struct bt_message *msg)
+{
+       struct bt_message_packet *packet_msg = (void *) msg;
+
+       BT_ASSERT(msg);
+       return packet_msg->packet->stream->class->default_clock_class;
+}
+
+const struct bt_clock_class *
+bt_message_packet_beginning_borrow_stream_class_default_clock_class_const(
+               const struct bt_message *msg)
+{
+       BT_ASSERT_PRE_NON_NULL(msg, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_PACKET_BEGINNING);
+       return borrow_packet_message_stream_class_default_clock_class(msg);
+}
+
+const struct bt_clock_class *
+bt_message_packet_end_borrow_stream_class_default_clock_class_const(
+               const struct bt_message *msg)
+{
+       BT_ASSERT_PRE_NON_NULL(msg, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_PACKET_END);
+       return borrow_packet_message_stream_class_default_clock_class(msg);
+}
index ccbe240a812a938ca6ae09ebe1df5ead54195b72..dbf88645ae0a29ff4ba76f3ddc90b20027328404 100644 (file)
@@ -269,3 +269,35 @@ void bt_message_stream_activity_end_set_default_clock_snapshot_state(
                BT_MESSAGE_TYPE_STREAM_ACTIVITY_END);
        set_stream_activity_message_default_clock_snapshot_state(msg, state);
 }
+
+static inline
+const struct bt_clock_class *
+borrow_stream_activity_message_stream_class_default_clock_class(
+               const struct bt_message *msg)
+{
+       struct bt_message_stream_activity *stream_act_msg = (void *) msg;
+
+       BT_ASSERT(msg);
+       return stream_act_msg->stream->class->default_clock_class;
+}
+
+const struct bt_clock_class *
+bt_message_stream_activity_beginning_borrow_stream_class_default_clock_class_const(
+               const struct bt_message *msg)
+{
+       BT_ASSERT_PRE_NON_NULL(msg, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(msg,
+               BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING);
+       return borrow_stream_activity_message_stream_class_default_clock_class(
+               msg);
+}
+
+const struct bt_clock_class *
+bt_message_stream_activity_end_borrow_stream_class_default_clock_class_const(
+               const struct bt_message *msg)
+{
+       BT_ASSERT_PRE_NON_NULL(msg, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_ACTIVITY_END);
+       return borrow_stream_activity_message_stream_class_default_clock_class(
+               msg);
+}
This page took 0.03135 seconds and 4 git commands to generate.