9#ifndef INCLUDED_BDLMT_MULTIQUEUETHREADPOOL
10#define INCLUDED_BDLMT_MULTIQUEUETHREADPOOL
398#include <bdlscm_version.h>
420#include <bsl_deque.h>
421#include <bsl_functional.h>
429class MultiQueueThreadPool;
449 e_ENQUEUING_DISABLED,
461 MultiQueueThreadPool *d_multiQueueThreadPool_p;
468 EnqueueState d_enqueueState;
490 MultiQueueThreadPool_Queue();
491 MultiQueueThreadPool_Queue(
const MultiQueueThreadPool_Queue&);
492 MultiQueueThreadPool_Queue &operator=(
const MultiQueueThreadPool_Queue &);
657 static const char s_defaultThreadName[16];
666 bool d_threadPoolIsOwned;
854 int *numDeleted = 0);
944 int *numDeleted = 0)
const;
973 return 0 == d_list.
size() && ( e_NOT_SCHEDULED == d_runState
974 || e_PAUSED == d_runState);
982 return e_ENQUEUING_ENABLED == d_enqueueState;
990 return e_PAUSED == d_runState;
998 return static_cast<int>(d_list.
size());
1007int MultiQueueThreadPool::findIfUsable(
int id,
1010 if ( e_STATE_RUNNING != d_state
1011 || 0 == d_threadPool_p->
enabled()) {
1017 if (d_queueRegistry.
end() == iter) {
1021 *queue = iter->second;
1034 if (findIfUsable(
id, &queue)) {
1053 if (findIfUsable(
id, &queue)) {
1057 if (0 == queue->
pushBack(functor)) {
1074 *numExecuted = d_numExecuted.
swap(0);
1076 *numDeleted = d_numDeleted.
swap(0);
1081 *numEnqueued = d_numEnqueued.
swap(0);
1093 if (findIfUsable(
id, &queue)) {
1110 if (d_queueRegistry.
end() != iter) {
1111 return iter->second->batchSize();
1124 if (d_queueRegistry.
end() != iter) {
1125 return iter->second->isEnabled();
1138 if (d_queueRegistry.
end() != iter) {
1139 return iter->second->isPaused();
1150 return -(d_numExecuted + d_numDeleted) + d_numEnqueued;
1160 if (d_queueRegistry.
end() != iter) {
1161 return iter->second->length();
1170 int *numDeleted)
const
1175 *numExecuted = d_numExecuted;
1177 *numDeleted = d_numDeleted;
1179 *numEnqueued = d_numEnqueued;
1187 return static_cast<int>(d_queueRegistry.
size());
1193 return *d_threadPool_p;
Definition bdlcc_objectpool.h:444
Definition bdlcc_objectpool.h:686
Definition bdlmt_multiqueuethreadpool.h:438
bool isPaused() const
Report whether this object is paused.
Definition bdlmt_multiqueuethreadpool.h:986
int pushBack(const Job &functor)
BSLMF_NESTED_TRAIT_DECLARATION(MultiQueueThreadPool_Queue, bslma::UsesBslmaAllocator)
bool isDrained() const
Report whether all jobs in this queue are finished.
Definition bdlmt_multiqueuethreadpool.h:969
bsl::function< void()> Job
Definition bdlmt_multiqueuethreadpool.h:442
~MultiQueueThreadPool_Queue()
Destroy this queue.
int batchSize() const
Definition bdlmt_multiqueuethreadpool.h:961
int pushFront(const Job &functor)
void setBatchSize(int batchSize)
bool enqueueDeletion(const Job &cleanupFunctor=Job(), bslmt::Latch *completionSignal=0)
MultiQueueThreadPool_Queue(MultiQueueThreadPool *multiQueueThreadPool, bslma::Allocator *basicAllocator=0)
bool isEnabled() const
Definition bdlmt_multiqueuethreadpool.h:978
void drainWaitWhilePausing()
Block until all threads waiting for this queue to pause are released.
int length() const
Return an instantaneous snapshot of the length of this queue.
Definition bdlmt_multiqueuethreadpool.h:994
Definition bdlmt_multiqueuethreadpool.h:636
MultiQueueThreadPool(const bslmt::ThreadAttributes &threadAttributes, int minThreads, int maxThreads, int maxIdleTime, bslma::Allocator *basicAllocator=0)
bsl::function< void()> Job
Definition bdlmt_multiqueuethreadpool.h:651
bool isPaused(int id) const
Definition bdlmt_multiqueuethreadpool.h:1132
int numElements() const
Definition bdlmt_multiqueuethreadpool.h:1146
int enqueueJob(int id, const Job &functor)
Definition bdlmt_multiqueuethreadpool.h:1047
void numProcessedReset(int *numExecuted, int *numEnqueued, int *numDeleted=0)
Definition bdlmt_multiqueuethreadpool.h:1066
int setBatchSize(int id, int batchSize)
Definition bdlmt_multiqueuethreadpool.h:1085
const ThreadPool & threadPool() const
Definition bdlmt_multiqueuethreadpool.h:1191
int batchSize(int id) const
Definition bdlmt_multiqueuethreadpool.h:1104
int addJobAtFront(int id, const Job &functor)
Definition bdlmt_multiqueuethreadpool.h:1028
void numProcessed(int *numExecuted, int *numEnqueued, int *numDeleted=0) const
Definition bdlmt_multiqueuethreadpool.h:1168
int deleteQueue(int id, const CleanupFunctor &cleanupFunctor)
bool isEnabled(int id) const
Definition bdlmt_multiqueuethreadpool.h:1118
friend class MultiQueueThreadPool_Queue
Definition bdlmt_multiqueuethreadpool.h:639
int numQueues() const
Definition bdlmt_multiqueuethreadpool.h:1183
BSLMF_NESTED_TRAIT_DECLARATION(MultiQueueThreadPool, bslma::UsesBslmaAllocator)
bsl::map< int, MultiQueueThreadPool_Queue * > QueueRegistry
Definition bdlmt_multiqueuethreadpool.h:653
MultiQueueThreadPool(ThreadPool *threadPool, bslma::Allocator *basicAllocator=0)
bsl::function< void()> CleanupFunctor
Definition bdlmt_multiqueuethreadpool.h:652
Definition bdlmt_threadpool.h:449
int enabled() const
Return the state (enabled or not) of the thread pool.
Definition bdlmt_threadpool.h:775
size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements contained by this deque.
Definition bslstl_deque.h:2074
Definition bslstl_deque.h:772
Forward declaration.
Definition bslstl_function.h:934
Definition bslstl_map.h:619
BloombergLP::bslstl::TreeIterator< const value_type, Node, difference_type > const_iterator
Definition bslstl_map.h:724
iterator end() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_map.h:2759
iterator find(const key_type &key)
Definition bslstl_map.h:1542
size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements in this map.
Definition bslstl_map.h:3518
BloombergLP::bslstl::TreeIterator< value_type, Node, difference_type > iterator
Definition bslstl_map.h:722
Definition bslma_allocator.h:457
Definition bslmt_condition.h:220
Definition bslmt_latch.h:349
Definition bslmt_lockguard.h:234
Definition bslmt_mutex.h:315
Definition bslmt_readlockguard.h:287
Definition bslmt_readerwritermutex.h:244
Definition bslmt_threadattributes.h:356
Definition bslmt_writelockguard.h:221
Definition bsls_atomic.h:743
int swap(int swapValue)
Definition bsls_atomic.h:1690
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlmt_eventscheduler.h:522
bsl::function< void(void *, bslma::Allocator *)> DefaultCreator
Definition bdlcc_objectpool.h:419
Definition bslma_usesbslmaallocator.h:343
Imp::Handle Handle
Definition bslmt_threadutil.h:385