Skip to content

Commit 19d123f

Browse files
JordanYateskartben
authored andcommitted
doc: zbus: update CONFIG_ZBUS_RUNTIME_OBSERVERS
Update the documentation for `CONFIG_ZBUS_RUNTIME_OBSERVERS`. Signed-off-by: Jordan Yates <[email protected]>
1 parent ab34a9d commit 19d123f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

doc/services/zbus/index.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -848,25 +848,28 @@ 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 in runtime. This feature uses the heap to allocate the
852-
nodes dynamically. The heap size limits the number of dynamic observers zbus can create. Therefore,
853-
set the :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS` to enable the feature. It is possible to
854-
adjust the heap size by changing the configuration :kconfig:option:`CONFIG_HEAP_MEM_POOL_SIZE`. The
855-
following example illustrates the runtime registration usage.
856-
857-
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``.
858856

859857
.. code-block:: c
860858
861859
ZBUS_LISTENER_DEFINE(my_listener, callback);
862860
// ...
863861
void thread_entry(void) {
862+
static struct zbus_observer_node obs_node;
864863
// ...
865864
/* Adding the observer to channel chan1 */
866-
zbus_chan_add_obs(&chan1, &my_listener, K_NO_WAIT);
865+
zbus_chan_add_obs(&chan1, &my_listener, &obs_node, K_NO_WAIT);
867866
/* Removing the observer from channel chan1 */
868867
zbus_chan_rm_obs(&chan1, &my_listener, K_NO_WAIT);
869868
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`.
870873

871874
Samples
872875
*******

0 commit comments

Comments
 (0)