Skip to content

Commit 8bfd256

Browse files
committed
lib: queued_operation: add API for managing a queue of operations
Full asynchronous support for APIs such as bus transactions generally requires managing operations from unrelated clients. This API provides a data structure and functions to manage those operations generically, leaving the service to provide only the service-specific operation description and implementation. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
1 parent 714f4ea commit 8bfd256

File tree

8 files changed

+2149
-0
lines changed

8 files changed

+2149
-0
lines changed

doc/reference/resource_management/index.rst

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,61 @@ state.
8686

8787
.. doxygengroup:: resource_mgmt_onoff_apis
8888
:project: Zephyr
89+
90+
.. _resource_mgmt_queued_operation:
91+
92+
Queued Operation Manager
93+
************************
94+
95+
While :ref:`resource_mgmt_onoff` supports a shared resource that must be
96+
available as long as any user still depends on it, the queued operation
97+
manager provides serialized exclusive access to a resource that executes
98+
operations asynchronously. This can be used to support (for example)
99+
ADC sampling for different sensors, or groups of bus transactions.
100+
Clients submit a operation request that is processed when the device
101+
becomes available, with clients being notified of the completion of the
102+
operation though the standard :ref:`async_notification`.
103+
104+
As with the on-off manager, the queued resource manager is a generic
105+
infrastructure tool that should be used by a extending service, such as
106+
an I2C bus controller or an ADC. The manager has the following
107+
characteristics:
108+
109+
* The stable states are idle and processing. The manager always begins
110+
in the idle state.
111+
* The core client operations are submit (add an operation) and cancel
112+
(remove an operation before it starts).
113+
* Ownership of the operation object transitions from the client to the
114+
manager when a queue request is accepted, and is returned to the
115+
client when the manager notifies the client of operation completion.
116+
* The core client event is completion. Manager state changes only as a
117+
side effect from submitting or completing an operation.
118+
* The service transitions from idle to processing when an operation is
119+
submitted.
120+
* The service transitions from processing to idle when notification of
121+
the last operation has completed and there are no queued operations.
122+
* The manager selects the next operation to process when notification of
123+
completion has itself completed. In particular, changes to the set of
124+
pending operations that are made during a completion callback affect
125+
the next operation to execute.
126+
* Each submitted operation includes a priority that orders execution by
127+
first-come-first-served within priority.
128+
* Operations are asynchronous, with completion notification through the
129+
:ref:`async_notification`. The operations and notifications are run
130+
in a context that is service-specific. This may be one or more
131+
dedicated threads, or work queues. Notifications may come from
132+
interrupt handlers. Note that operations may complete before the
133+
submit request has returned to its caller.
134+
135+
The generic infrastructure holds the active operation and a queue of
136+
pending operations. A service extension shall provide functions that:
137+
138+
* check that a request is well-formed, i.e. can be added to the queue;
139+
* receive notification that a new operation is to be processed, or that
140+
no operations are available (allowing the service to enter a
141+
power-down mode);
142+
* translate a generic completion callback into a service-specific
143+
callback.
144+
145+
.. doxygengroup:: resource_mgmt_queued_operation_apis
146+
:project: Zephyr

0 commit comments

Comments
 (0)