lib: create input port msg iterator from self {msg iterator, sink comp.}
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 20 Jul 2019 21:16:24 +0000 (17:16 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 24 Jul 2019 14:17:16 +0000 (10:17 -0400)
commitca02df0ad8ae9a1a3640956d91ca31059d0b203a
tree8b2b678d8fa2620f65ae836965147d109591577c
parent51f97fcc8c58d17aa224c150735f7e256e796f4e
lib: create input port msg iterator from self {msg iterator, sink comp.}

This patch makes an input port message iterator have a link to the
upstream message iterators it needs and vice versa.

The motivation behind this is to eventually be able to transmit some
state or property automatically to all the upstream message iterators,
recursively, of a given message iterator without any special user code.

For example, consider this graph of message iterators (arrow means "is
an upstream message iterator of"):

    A <──┐
         ├──┬── C <──┬── F
    B <──┘  │        │
            │   E <──┘
    D <─────┘

                G <───── H

Here, setting the state/property on F would also set it on A, B, D, C,
and E. Setting it on C would set it on A, B, and D. Setting it on H
would only set it on G.

The message iterator graph, which can be considered like another,
"dynamic" graph on top of the static component graph used only to limit
a message iterator graph's topology, is always directed and acyclic,
where each node has a single parent. In other words, it is not permitted
that two message iterators use the same downstream message iterator, for
example:

    A <──┐
         ├───── C <───── F
    B <──┘      │        │
                │        │
    D <─────────┴────────┘

(D has both C and F as parents).

This is so that each message iterator and its upstream message iterators
constitute a single, private state.

This patch replaces
bt_self_component_port_input_message_iterator_create() with
bt_self_component_port_input_message_iterator_create_from_message_iterator()
and
bt_self_component_port_input_message_iterator_create_from_sink_component().

bt_self_component_port_input_message_iterator_create_from_sink_component()
does nothing with the self sink component parameter (except checking
that it's not `NULL`), but it's needed to make the functions type safe.

Internally, an input port message iterator contains both a weak pointer
to its downstream message iterator and an array of weak pointers to its
upstream message iterators.

When you create a message iterator with
bt_self_component_port_input_message_iterator_create_from_message_iterator(),
the function sets the new message iterator's downstream message iterator
to the provided self message iterator. It also adds the new message
iterator to the self message iterator's array of upstream message
iterators.

On message iterator finalization:

* The message iterator removes itself as the downstream message iterator
  of all its upstream message iterators. It also clears the upstream
  message iterator array.

* The message iterator removes itself as one of the upstream message
  iterators of its downstream message iterator.

I didn't find any race condition regarding the new message iterator
links, but I could be wrong. The future and more tests will tell us.

In the `bt2` Python package:

* _UserComponentInputPort.create_message_iterator() is removed.

* _UserMessageIterator._create_input_port_message_iterator() is added
  (accepts a user component input port).

* _UserSinkComponent._create_input_port_message_iterator() is added
  (accepts a user component input port).

Tests are updated accordingly.

I added a test for
_UserMessageIterator._create_input_port_message_iterator() specifically
(needs a filter message iterator) because we use
_UserSinkComponent._create_input_port_message_iterator() in the current
tests.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I46cefca445353c453fbd9404b97687b81fa5f443
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1732
18 files changed:
include/babeltrace2/graph/self-component-port-input-message-iterator.h
src/bindings/python/bt2/bt2/component.py
src/bindings/python/bt2/bt2/message_iterator.py
src/bindings/python/bt2/bt2/port.py
src/lib/graph/component-class-sink-colander.c
src/lib/graph/iterator.c
src/lib/graph/message/iterator.h
src/plugins/ctf/fs-sink/fs-sink.c
src/plugins/lttng-utils/debug-info/debug-info.c
src/plugins/text/details/details.c
src/plugins/text/pretty/pretty.c
src/plugins/utils/counter/counter.c
src/plugins/utils/dummy/dummy.c
src/plugins/utils/muxer/muxer.c
src/plugins/utils/trimmer/trimmer.c
tests/bindings/python/bt2/test_error.py
tests/bindings/python/bt2/test_graph.py
tests/bindings/python/bt2/test_message_iterator.py
This page took 0.026685 seconds and 4 git commands to generate.