C/C++ API Reference
Loading...
Searching...
No Matches
pw_work_queue

Oveview

Main docs: https://pigweed.dev/pw_work_queue.

Classes

class  pw::work_queue::CustomWorkQueue< WorkItem >
 
class  pw::work_queue::WorkQueue
 
struct  pw::work_queue::internal::Storage< WorkItem, kWorkQueueEntries >
 
class  pw::work_queue::CustomWorkQueueWithBuffer< kWorkQueueEntries, WorkItem >
 
class  pw::work_queue::WorkQueueWithBuffer< kWorkQueueEntries >
 

Functions

 pw::work_queue::CustomWorkQueue< WorkItem >::CustomWorkQueue (InlineQueue< WorkItem > &queue, pw::Function< void(WorkItem &)> &&fn)
 
Status pw::work_queue::CustomWorkQueue< WorkItem >::PushWork (WorkItem &&work_item)
 
void pw::work_queue::CustomWorkQueue< WorkItem >::CheckPushWork (WorkItem &&work_item)
 
void pw::work_queue::CustomWorkQueue< WorkItem >::CheckPushWork (WorkItem &work_item)
 
void pw::work_queue::CustomWorkQueue< WorkItem >::RequestStop ()
 
 pw::work_queue::WorkQueue::WorkQueue (InlineQueue< Closure > &queue)
 
constexpr pw::work_queue::CustomWorkQueueWithBuffer< kWorkQueueEntries, WorkItem >::CustomWorkQueueWithBuffer (pw::Function< void(WorkItem &)> &&fn)
 

Variables

InlineQueue< WorkItem, kWorkQueueEntries > pw::work_queue::internal::Storage< WorkItem, kWorkQueueEntries >::queue
 

Function Documentation

◆ CheckPushWork()

template<typename WorkItem >
void pw::work_queue::CustomWorkQueue< WorkItem >::CheckPushWork ( WorkItem &&  work_item)
inline

Queues work for execution. Crashes if the work cannot be queued due to a full queue or a stopped worker thread.

This call is recommended where possible since it saves error handling code at the callsite; and in many practical cases, it is a bug if the work queue is full (and so a crash is useful to detect the problem).

Parameters
[in]work_itemThe entry to enqueue.
Precondition
  • The queue must not overflow, i.e. be full.
  • The queue must not have been requested to stop, i.e. it must not be in the process of shutting down.

◆ CustomWorkQueue()

template<typename WorkItem >
pw::work_queue::CustomWorkQueue< WorkItem >::CustomWorkQueue ( InlineQueue< WorkItem > &  queue,
pw::Function< void(WorkItem &)> &&  fn 
)
inline
Parameters
[in]queueThe work entries to enqueue.
[in]fnThe function to invoke on each enqueued WorkItem
Note
The ThreadNotification prevents this from being constexpr.

◆ CustomWorkQueueWithBuffer()

template<size_t kWorkQueueEntries, typename WorkItem >
constexpr pw::work_queue::CustomWorkQueueWithBuffer< kWorkQueueEntries, WorkItem >::CustomWorkQueueWithBuffer ( pw::Function< void(WorkItem &)> &&  fn)
inlineconstexpr
Parameters
[in]fnThe function to invoke on each enqueued WorkItem

◆ PushWork()

template<typename WorkItem >
Status pw::work_queue::CustomWorkQueue< WorkItem >::PushWork ( WorkItem &&  work_item)
inline

Enqueues a work_item for execution by the work queue thread.

Parameters
[in]work_itemThe entry to enqueue.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*     OK: Success. Entry was enqueued for execution.
* 
*     FAILED_PRECONDITION: The work queue is shutting down. Entries are no
*     longer permitted.
* 
*     RESOURCE_EXHAUSTED: Internal work queue is full. Entry was not
*     enqueued.
* 
*  

◆ RequestStop()

template<typename WorkItem >
void pw::work_queue::CustomWorkQueue< WorkItem >::RequestStop ( )
inline

Locks the queue to prevent further work enqueing, finishes outstanding work, then shuts down the worker thread.

The WorkQueue cannot be resumed after stopping because the ThreadCore thread returns and may be joined. The WorkQueue must be reconstructed for re-use after the thread has been joined.

◆ WorkQueue()

pw::work_queue::WorkQueue::WorkQueue ( InlineQueue< Closure > &  queue)
inline
Parameters
[in]queueThe work entries to enqueue.