xref: /aosp_15_r20/external/pigweed/pw_work_queue/docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_work_queue:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker=============
4*61c4878aSAndroid Build Coastguard Workerpw_work_queue
5*61c4878aSAndroid Build Coastguard Worker=============
6*61c4878aSAndroid Build Coastguard WorkerThe ``pw_work_queue`` module contains utilities for deferring work to be
7*61c4878aSAndroid Build Coastguard Workerexecuted by another thread.
8*61c4878aSAndroid Build Coastguard Worker
9*61c4878aSAndroid Build Coastguard Worker.. warning::
10*61c4878aSAndroid Build Coastguard Worker
11*61c4878aSAndroid Build Coastguard Worker   This module is still under construction; the API is not yet stable.
12*61c4878aSAndroid Build Coastguard Worker
13*61c4878aSAndroid Build Coastguard Worker-------
14*61c4878aSAndroid Build Coastguard WorkerExample
15*61c4878aSAndroid Build Coastguard Worker-------
16*61c4878aSAndroid Build Coastguard Worker
17*61c4878aSAndroid Build Coastguard Worker.. code-block:: cpp
18*61c4878aSAndroid Build Coastguard Worker
19*61c4878aSAndroid Build Coastguard Worker   #include "pw_thread/detached_thread.h"
20*61c4878aSAndroid Build Coastguard Worker   #include "pw_work_queue/work_queue.h"
21*61c4878aSAndroid Build Coastguard Worker
22*61c4878aSAndroid Build Coastguard Worker   pw::work_queue::WorkQueueWithBuffer<10> work_queue;
23*61c4878aSAndroid Build Coastguard Worker
24*61c4878aSAndroid Build Coastguard Worker   pw::thread::Options& WorkQueueThreadOptions();
25*61c4878aSAndroid Build Coastguard Worker   void SomeLongRunningProcessing();
26*61c4878aSAndroid Build Coastguard Worker
27*61c4878aSAndroid Build Coastguard Worker   void SomeInterruptHandler() {
28*61c4878aSAndroid Build Coastguard Worker       // Instead of executing the long running processing task in the interrupt,
29*61c4878aSAndroid Build Coastguard Worker       // the work_queue executes it on the interrupt's behalf.
30*61c4878aSAndroid Build Coastguard Worker       work_queue.CheckPushWork(SomeLongRunningProcessing);
31*61c4878aSAndroid Build Coastguard Worker   }
32*61c4878aSAndroid Build Coastguard Worker
33*61c4878aSAndroid Build Coastguard Worker   int main() {
34*61c4878aSAndroid Build Coastguard Worker       // Start up the work_queue as a detached thread which runs forever.
35*61c4878aSAndroid Build Coastguard Worker       pw::thread::DetachedThread(WorkQueueThreadOptions(), work_queue);
36*61c4878aSAndroid Build Coastguard Worker   }
37*61c4878aSAndroid Build Coastguard Worker
38*61c4878aSAndroid Build Coastguard Worker-------------
39*61c4878aSAndroid Build Coastguard WorkerAPI reference
40*61c4878aSAndroid Build Coastguard Worker-------------
41*61c4878aSAndroid Build Coastguard Worker.. doxygennamespace:: pw::work_queue
42*61c4878aSAndroid Build Coastguard Worker   :members:
43