Skip to content

Commit 6cd508f

Browse files
rodrigopexkartben
authored andcommitted
doc: zbus: Runtime observers pool
Add documentation of the runtime observers pool. Signed-off-by: Rodrigo Peixoto <rodrigopex@gmail.com>
1 parent 67d24b9 commit 6cd508f

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

doc/services/zbus/index.rst

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -848,29 +848,36 @@ The following code has the exact behavior of the code in :ref:`reading from a ch
848848
Runtime observer registration
849849
-----------------------------
850850

851-
It is possible to add observers to channels at runtime if
852-
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS` is enabled. In addition to the channel and observer
853-
references, :c:func:`zbus_chan_add_obs` also requires a :c:struct:`zbus_observer_node` to link the two
854-
together, which must remain valid in memory for the duration that the observer is attached to the
855-
channel. The simplest way to achieve this is to make the structure ``static``.
851+
It is possible to add observers to channels in runtime. Set the
852+
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS` to enable the feature. This feature uses the heap to
853+
allocate the nodes dynamically, a memory slab to allocate the nodes statically, or user-provided
854+
nodes. It depends on the :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC`, which can be
855+
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_DYNAMIC`,
856+
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_STATIC`, and
857+
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_NONE`. The dynamic is the default. When
858+
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_STATIC` is enabled, you need to set the
859+
number of runtime observers you are going to use by setting the
860+
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_POOL_SIZE` configuration. The following example
861+
illustrates the runtime registration usage.
856862

857863
.. code-block:: c
858864
859865
ZBUS_LISTENER_DEFINE(my_listener, callback);
860866
// ...
861867
void thread_entry(void) {
862-
static struct zbus_observer_node obs_node;
863868
// ...
864869
/* Adding the observer to channel chan1 */
865-
zbus_chan_add_obs(&chan1, &my_listener, &obs_node, K_NO_WAIT);
870+
zbus_chan_add_obs(&chan1, &my_listener, K_NO_WAIT);
866871
/* Removing the observer from channel chan1 */
867872
zbus_chan_rm_obs(&chan1, &my_listener, K_NO_WAIT);
868873
874+
869875
.. warning::
870876

871-
The :c:struct:`zbus_observer_node` can only be re-used in :c:func:`zbus_chan_add_obs` after removing
877+
The :c:struct:`zbus_observer_node` can only be re-used in :c:func:`zbus_chan_add_obs_with_node` after removing
872878
the channel observer it was first associated with through :c:func:`zbus_chan_rm_obs`.
873879

880+
874881
Samples
875882
*******
876883

@@ -936,7 +943,15 @@ Related configuration options:
936943
a pool for the message subscriber for a set of channels;
937944
* :kconfig:option:`CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC_DATA_SIZE` the biggest message of zbus
938945
channels to be transported into a message buffer;
939-
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS` enables the runtime observer registration.
946+
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS` enables the runtime observer registration;
947+
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_DYNAMIC` allocate the runtime observers
948+
dynamically using the heap;
949+
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_STATIC` allocate the runtime observers
950+
statically using a memory slab;
951+
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_POOL_SIZE` the amount of enabled runtime
952+
observers to statically allocate.
953+
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_NONE` use user-provided runtime
954+
observers nodes;
940955

941956
API Reference
942957
*************

0 commit comments

Comments
 (0)