BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlmt::MultiQueueThreadPool_Queue Class Reference

#include <bdlmt_multiqueuethreadpool.h>

Public Types

typedef bsl::function< void()> Job
 

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (MultiQueueThreadPool_Queue, bslma::UsesBslmaAllocator)
 
 MultiQueueThreadPool_Queue (MultiQueueThreadPool *multiQueueThreadPool, bslma::Allocator *basicAllocator=0)
 
 ~MultiQueueThreadPool_Queue ()
 Destroy this queue.
 
int enable ()
 
int disable ()
 
void drainWaitWhilePausing ()
 Block until all threads waiting for this queue to pause are released.
 
void executeFront ()
 
bool enqueueDeletion (const Job &cleanupFunctor=Job(), bslmt::Latch *completionSignal=0)
 
int initiatePause ()
 
int pushBack (const Job &functor)
 
int pushFront (const Job &functor)
 
void reset ()
 
int resume ()
 
void setBatchSize (int batchSize)
 
void waitWhilePausing ()
 
int batchSize () const
 
bool isDrained () const
 Report whether all jobs in this queue are finished.
 
bool isEnabled () const
 
bool isPaused () const
 Report whether this object is paused.
 
int length () const
 Return an instantaneous snapshot of the length of this queue.
 

Detailed Description

This private class provides a thread-safe, lightweight job queue.

See bdlmt_multiqueuethreadpool

Member Typedef Documentation

◆ Job

Constructor & Destructor Documentation

◆ MultiQueueThreadPool_Queue()

bdlmt::MultiQueueThreadPool_Queue::MultiQueueThreadPool_Queue ( MultiQueueThreadPool multiQueueThreadPool,
bslma::Allocator basicAllocator = 0 
)
explicit

Create a MultiQueueThreadPool_Queue with an initial capacity of 0 and initialized to use the specified multiQueueThreadPool to track aggregate values (e.g., the number of active queues) and to obtain the thread pool used to execute jobs that are appended to this queue. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the default memory allocator is used.

◆ ~MultiQueueThreadPool_Queue()

bdlmt::MultiQueueThreadPool_Queue::~MultiQueueThreadPool_Queue ( )

Member Function Documentation

◆ batchSize()

int bdlmt::MultiQueueThreadPool_Queue::batchSize ( ) const
inline

Return an instantaneous snapshot of the execution batch size (see {Job Execution Batch Size}). When a thread is selecting jobs for processing, if fewer than batchSize jobs are available then only the available jobs will be processed in the current batch.

◆ BSLMF_NESTED_TRAIT_DECLARATION()

bdlmt::MultiQueueThreadPool_Queue::BSLMF_NESTED_TRAIT_DECLARATION ( MultiQueueThreadPool_Queue  ,
bslma::UsesBslmaAllocator   
)

◆ disable()

int bdlmt::MultiQueueThreadPool_Queue::disable ( )

Disable enqueuing to this queue. Return 0 on success, and a non-zero value otherwise. This method will fail (with an error) if prepareForDeletion has already been called on this object.

◆ drainWaitWhilePausing()

void bdlmt::MultiQueueThreadPool_Queue::drainWaitWhilePausing ( )

◆ enable()

int bdlmt::MultiQueueThreadPool_Queue::enable ( )

Enable enqueuing to this queue. Return 0 on success, and a non-zero value otherwise. This method will fail (with an error) if prepareForDeletion has already been called on this object.

◆ enqueueDeletion()

bool bdlmt::MultiQueueThreadPool_Queue::enqueueDeletion ( const Job cleanupFunctor = Job(),
bslmt::Latch completionSignal = 0 
)

Permanently disable enqueueing from this queue, and enqueue a job that will delete this queue. Optionally specify cleanupFunctor, which, if supplied, will be invoked immediately prior to this queue's deletion. Optionally specify completionSignal, on which (if the calling thread is not processing a job - or batch of jobs - for this queue) to invoke arrive when the queue is deleted. Return true if the current thread is the thread processing a job (or batch of jobs), and false otherwise. Note that if completionSignal is supplied, a return status of false typically indicates that completionSignal->wait() should be invoked from the calling function', while a return status of true indicates this is an attempt to delete the queue from within a job being processed on the queue (so waiting on the queue's deletion would result in a dead-lock).

◆ executeFront()

void bdlmt::MultiQueueThreadPool_Queue::executeFront ( )

Execute the Job at the front of this queue, dequeue the Job, and if the queue is not paused schedule a callback from the associated thread pool. The behavior is undefined if this queue is empty.

◆ initiatePause()

int bdlmt::MultiQueueThreadPool_Queue::initiatePause ( )

Initiate the pausing of this queue, prevent jobs from being executed on this queue (excluding the currently-executing job - or batch of jobs - if there is one), and prevent the queue from being deleted. Return 0 on success, and a non-zero value if the queue is already paused or is being paused or deleted by another thread. The behavior is undefined unless, after a successful invocation of initiatePause, waitWhilePausing is invoked (to complete the pause operation and allow the queue to, potentially, be deleted).

◆ isDrained()

bool bdlmt::MultiQueueThreadPool_Queue::isDrained ( ) const
inline

◆ isEnabled()

bool bdlmt::MultiQueueThreadPool_Queue::isEnabled ( ) const
inline

Report whether enqueuing to this object is enabled. This object is constructed with enqueuing enabled.

◆ isPaused()

bool bdlmt::MultiQueueThreadPool_Queue::isPaused ( ) const
inline

◆ length()

int bdlmt::MultiQueueThreadPool_Queue::length ( ) const
inline

◆ pushBack()

int bdlmt::MultiQueueThreadPool_Queue::pushBack ( const Job functor)

Enqueue the specified functor at the end of this queue. Return 0 on success, and a non-zero value if enqueuing is disabled.

◆ pushFront()

int bdlmt::MultiQueueThreadPool_Queue::pushFront ( const Job functor)

Add the specified functor at the front of this queue. Return 0 on success, and a non-zero value if enqueuing is disabled.

◆ reset()

void bdlmt::MultiQueueThreadPool_Queue::reset ( )

Reset this queue to its initial state. The behavior is undefined unless this queue's lock is in an unlocked state. After this method returns, the object is ready for use as though it were a new object. Note that this method is not thread-safe and is used by the object pool contained within *d_multiQueueThreadPool_p.

◆ resume()

int bdlmt::MultiQueueThreadPool_Queue::resume ( )

Allow jobs on the queue to begin executing. Return 0 on success, and a non-zero value if the queue is not paused or !d_list.empty() and the associated thread pool fails to enqueue a job.

◆ setBatchSize()

void bdlmt::MultiQueueThreadPool_Queue::setBatchSize ( int  batchSize)

Configure this queue to process jobs in groups of the specified batchSize (see {Job Execution Batch Size}). When a thread is selecting jobs for processing, if fewer than batchSize jobs are available then only the available jobs will be processed in the current batch. The behavior is undefined unless 1 <= batchSize. Note that the initial value for the execution batch size is 1 for all queues.

◆ waitWhilePausing()

void bdlmt::MultiQueueThreadPool_Queue::waitWhilePausing ( )

Wait until any currently-executing job on the queue completes and the queue is paused. Note that pausing differs from disable in that (1) pause stops processing for a queue, and (2) does not prevent additional jobs from being enqueued. The behavior of this method is undefined unless it is invoked after a successful initiatePause invocation.


The documentation for this class was generated from the following file: