Skip to content

Commit e235a83

Browse files
committed
doc: zbus: Runtime observers pool
Add documentation of the runtime observers pool. Signed-off-by: Rodrigo Peixoto <[email protected]>
1 parent 1e73136 commit e235a83

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

doc/services/zbus/index.rst

+20-12
Original file line numberDiff line numberDiff line change
@@ -848,28 +848,30 @@ 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 or a memory slab to allocate the nodes statically. It depends on the
854+
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC` which can be
855+
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_DYNAMIC` and
856+
:kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_STATIC`. When the heap is enabled, the
857+
dynamic one is automatically chosen. 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.
862+
856863

857864
.. code-block:: c
858865
859866
ZBUS_LISTENER_DEFINE(my_listener, callback);
860867
// ...
861868
void thread_entry(void) {
862-
static struct zbus_observer_node obs_node;
863869
// ...
864870
/* Adding the observer to channel chan1 */
865-
zbus_chan_add_obs(&chan1, &my_listener, &obs_node, K_NO_WAIT);
871+
zbus_chan_add_obs(&chan1, &my_listener, K_NO_WAIT);
866872
/* Removing the observer from channel chan1 */
867873
zbus_chan_rm_obs(&chan1, &my_listener, K_NO_WAIT);
868874
869-
.. warning::
870-
871-
The :c:struct:`zbus_observer_node` can only be re-used in :c:func:`zbus_chan_add_obs` after removing
872-
the channel observer it was first associated with through :c:func:`zbus_chan_rm_obs`.
873875
874876
Samples
875877
*******
@@ -936,7 +938,13 @@ Related configuration options:
936938
a pool for the message subscriber for a set of channels;
937939
* :kconfig:option:`CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC_DATA_SIZE` the biggest message of zbus
938940
channels to be transported into a message buffer;
939-
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS` enables the runtime observer registration.
941+
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS` enables the runtime observer registration;
942+
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_STATIC` allocate the runtime observers
943+
statically using a memory slab;
944+
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_ALLOC_DYNAMIC` allocate the runtime observers
945+
dynamically using the heap;
946+
* :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_POOL_SIZE` the amount of enabled runtime
947+
observers to statically allocate.
940948

941949
API Reference
942950
*************

0 commit comments

Comments
 (0)