zephyr/samples/subsys/zbus/work_queue
Keith Packard 0b90fd5adf samples, tests, boards: Switch main return type from void to int
As both C and C++ standards require applications running under an OS to
return 'int', adapt that for Zephyr to align with those standard. This also
eliminates errors when building with clang when not using -ffreestanding,
and reduces the need for compiler flags to silence warnings for both clang
and gcc.

Most of these changes were automated using coccinelle with the following
script:

@@
@@
- void
+ int
main(...) {
	...
-	return;
+	return 0;
	...
}

Approximately 40 files had to be edited by hand as coccinelle was unable to
fix them.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-04-14 07:49:41 +09:00
..
src
CMakeLists.txt
prj.conf
README.rst
sample.yaml

.. _zbus-work-queue-sample:

Workqueue sample
################

Overview
********
This sample implements an application using zbus to illustrate three different reaction options. First, the observer can react "instantaneously" by using a listener callback. It can schedule a job, pushing that to the system work queue. Last, it can wait and execute that in a subscriber thread.

Building and Running
********************

This project outputs to the console.  It can be built and executed
on QEMU as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/subsys/zbus/work_queue
   :host-os: unix
   :board: qemu_x86
   :goals: run

Sample Output
=============

.. code-block:: console

    I: Sensor msg processed by CALLBACK fh1: temp = 10, press = 1, humidity = 100
    I: Sensor msg processed by CALLBACK fh2: temp = 10, press = 1, humidity = 100
    I: Sensor msg processed by CALLBACK fh3: temp = 10, press = 1, humidity = 100
    I: Sensor msg processed by WORK QUEUE handler dh1: temp = 10, press = 1, humidity = 100
    I: Sensor msg processed by WORK QUEUE handler dh2: temp = 10, press = 1, humidity = 100
    I: Sensor msg processed by WORK QUEUE handler dh3: temp = 10, press = 1, humidity = 100
    I: Sensor msg processed by THREAD handler 1: temp = 10, press = 1, humidity = 100
    I: Sensor msg processed by THREAD handler 2: temp = 10, press = 1, humidity = 100
    I: Sensor msg processed by THREAD handler 3: temp = 10, press = 1, humidity = 100
    I: Sensor msg processed by CALLBACK fh1: temp = 20, press = 2, humidity = 200
    I: Sensor msg processed by CALLBACK fh2: temp = 20, press = 2, humidity = 200
    I: Sensor msg processed by CALLBACK fh3: temp = 20, press = 2, humidity = 200
    I: Sensor msg processed by WORK QUEUE handler dh1: temp = 20, press = 2, humidity = 200
    I: Sensor msg processed by WORK QUEUE handler dh2: temp = 20, press = 2, humidity = 200
    I: Sensor msg processed by WORK QUEUE handler dh3: temp = 20, press = 2, humidity = 200
    I: Sensor msg processed by THREAD handler 1: temp = 20, press = 2, humidity = 200
    I: Sensor msg processed by THREAD handler 2: temp = 20, press = 2, humidity = 200
    I: Sensor msg processed by THREAD handler 3: temp = 20, press = 2, humidity = 200
    I: Sensor msg processed by CALLBACK fh1: temp = 30, press = 3, humidity = 300
    I: Sensor msg processed by CALLBACK fh2: temp = 30, press = 3, humidity = 300
    I: Sensor msg processed by CALLBACK fh3: temp = 30, press = 3, humidity = 300
    I: Sensor msg processed by WORK QUEUE handler dh1: temp = 30, press = 3, humidity = 300
    I: Sensor msg processed by WORK QUEUE handler dh2: temp = 30, press = 3, humidity = 300
    I: Sensor msg processed by WORK QUEUE handler dh3: temp = 30, press = 3, humidity = 300
    I: Sensor msg processed by THREAD handler 1: temp = 30, press = 3, humidity = 300
    I: Sensor msg processed by THREAD handler 2: temp = 30, press = 3, humidity = 300
    I: Sensor msg processed by THREAD handler 3: temp = 30, press = 3, humidity = 300
    <continues>

Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.