Browse Source

doc: zbus: Runtime observers pool

Add documentation of the runtime observers pool.

Signed-off-by: Rodrigo Peixoto <rodrigopex@gmail.com>
pull/88935/head
Rodrigo Peixoto 3 months ago committed by Benjamin Cabé
parent
commit
6cd508f111
  1. 33
      doc/services/zbus/index.rst

33
doc/services/zbus/index.rst

@ -848,29 +848,36 @@ The following code has the exact behavior of the code in :ref:`reading from a ch @@ -848,29 +848,36 @@ The following code has the exact behavior of the code in :ref:`reading from a ch
Runtime observer registration
-----------------------------
It is possible to add observers to channels at runtime if
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS` is enabled. In addition to the channel and observer
references, :c:func:`zbus_chan_add_obs` also requires a :c:struct:`zbus_observer_node` to link the two
together, which must remain valid in memory for the duration that the observer is attached to the
channel. The simplest way to achieve this is to make the structure ``static``.
It is possible to add observers to channels in runtime. Set the
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS` to enable the feature. This feature uses the heap to
allocate the nodes dynamically, a memory slab to allocate the nodes statically, or user-provided
nodes. It depends on the :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC`, which can be
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_DYNAMIC`,
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_STATIC`, and
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_NONE`. The dynamic is the default. When
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_STATIC` is enabled, you need to set the
number of runtime observers you are going to use by setting the
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_POOL_SIZE` configuration. The following example
illustrates the runtime registration usage.
.. code-block:: c
ZBUS_LISTENER_DEFINE(my_listener, callback);
// ...
void thread_entry(void) {
static struct zbus_observer_node obs_node;
// ...
/* Adding the observer to channel chan1 */
zbus_chan_add_obs(&chan1, &my_listener, &obs_node, K_NO_WAIT);
zbus_chan_add_obs(&chan1, &my_listener, K_NO_WAIT);
/* Removing the observer from channel chan1 */
zbus_chan_rm_obs(&chan1, &my_listener, K_NO_WAIT);
.. warning::
The :c:struct:`zbus_observer_node` can only be re-used in :c:func:`zbus_chan_add_obs` after removing
The :c:struct:`zbus_observer_node` can only be re-used in :c:func:`zbus_chan_add_obs_with_node` after removing
the channel observer it was first associated with through :c:func:`zbus_chan_rm_obs`.
Samples
*******
@ -936,7 +943,15 @@ Related configuration options: @@ -936,7 +943,15 @@ Related configuration options:
a pool for the message subscriber for a set of channels;
* :kconfig:option:`CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC_DATA_SIZE` the biggest message of zbus
channels to be transported into a message buffer;
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS` enables the runtime observer registration.
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS` enables the runtime observer registration;
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_DYNAMIC` allocate the runtime observers
dynamically using the heap;
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_STATIC` allocate the runtime observers
statically using a memory slab;
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_POOL_SIZE` the amount of enabled runtime
observers to statically allocate.
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_NONE` use user-provided runtime
observers nodes;
API Reference
*************

Loading…
Cancel
Save