16 #ifndef BLOOMBERG_QUANTUM_DISPATCHER_H 17 #define BLOOMBERG_QUANTUM_DISPATCHER_H 19 #include <quantum/quantum_context.h> 20 #include <quantum/quantum_configuration.h> 21 #include <quantum/quantum_macros.h> 48 DEPRECATED
Dispatcher(
int numCoroutineThreads = -1,
50 bool pinCoroutineThreadsToCores =
false);
74 template <
class RET = int,
class FUNC,
class ... ARGS>
76 post(FUNC&& func, ARGS&&... args);
94 template <
class RET = int,
class FUNC,
class ... ARGS>
96 post(
int queueId,
bool isHighPriority, FUNC&& func, ARGS&&... args);
109 template <
class RET = int,
class FUNC,
class ... ARGS>
129 template <
class RET = int,
class FUNC,
class ... ARGS>
131 postFirst(
int queueId,
bool isHighPriority, FUNC&& func, ARGS&&... args);
143 template <
class RET = int,
class FUNC,
class ... ARGS>
161 template <
class RET = int,
class FUNC,
class ... ARGS>
163 postAsyncIo(
int queueId,
bool isHighPriority, FUNC&& func, ARGS&&... args);
176 template <
class RET =
int,
class INPUT_IT,
class = Traits::IsInputIterator<INPUT_IT>>
182 template <
class RET =
int,
class INPUT_IT>
193 template <
class RET =
int,
class INPUT_IT,
class = Traits::IsInputIterator<INPUT_IT>>
199 template <
class RET =
int,
class INPUT_IT>
281 int queueId = (
int)
IQueue::QueueId::All) const;
291 int queueId = (
int)
IQueue::QueueId::All) const;
297 void drain(
std::chrono::milliseconds timeout =
std::chrono::milliseconds::zero());
325 int queueId = (
int)
IQueue::QueueId::All);
333 postImpl(
int queueId,
bool isHighPriority,
ITask::Type type, FUNC&& func, ARGS&&... args);
337 postAsyncIoImpl(
int queueId,
bool isHighPriority, FUNC&& func, ARGS&&... args);
342 std::atomic_flag _terminated;
349 #include <quantum/impl/quantum_dispatcher_impl.h> 351 #endif //BLOOMBERG_QUANTUM_DISPATCHER_H void drain(std::chrono::milliseconds timeout=std::chrono::milliseconds::zero())
Drains all queues on this dispatcher object.
Definition: quantum_dispatcher_impl.h:235
ThreadContextPtr< std::vector< std::vector< RET > > > forEachBatch(INPUT_IT first, INPUT_IT last, Functions::ForEachFunc< RET, INPUT_IT > func)
The batched version of forEach(). This function applies the given unary function to all the elements ...
Definition: quantum_dispatcher_impl.h:127
Definition: quantum_buffer_impl.h:22
QueueStatistics stats(IQueue::QueueType type=IQueue::QueueType::All, int queueId=(int) IQueue::QueueId::All)
Returns a statistics object for the specified type and queue id.
Definition: quantum_dispatcher_impl.h:285
ThreadContextPtr< RET > post(FUNC &&func, ARGS &&... args)
Post a coroutine to run asynchronously.
Definition: quantum_dispatcher_impl.h:52
Class implementing the dispatching logic unto worker threads. Used for both coroutines and IO tasks.
Definition: quantum_dispatcher_core.h:45
void terminate() final
Signal all threads to immediately terminate and exit. All other pending coroutines and IO tasks will ...
Definition: quantum_dispatcher_impl.h:212
Definition: quantum_stl_impl.h:23
ThreadContextPtr< std::map< KEY, REDUCED_TYPE > > mapReduce(INPUT_IT first, INPUT_IT last, Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT > mapper, Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE > reducer)
Implementation of map-reduce functionality.
Definition: quantum_dispatcher_impl.h:153
ThreadFuturePtr< RET > postAsyncIo(FUNC &&func, ARGS &&... args)
Post a blocking IO (or long running) task to run asynchronously on the IO thread pool.
Definition: quantum_dispatcher_impl.h:88
std::function< RET(const typename std::iterator_traits< INPUT_IT >::value_type &)> ForEachFunc
Definition: quantum_functions.h:34
ThreadContextPtr< std::map< KEY, REDUCED_TYPE > > mapReduceBatch(INPUT_IT first, INPUT_IT last, Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT > mapper, Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE > reducer)
This version of mapReduce() runs both the mapper and the reducer functions in batches for improved pe...
Definition: quantum_dispatcher_impl.h:185
ThreadContextPtr< RET > postFirst(FUNC &&func, ARGS &&... args)
Post the first coroutine in a continuation chain to run asynchronously.
Definition: quantum_dispatcher_impl.h:70
std::function< std::vector< std::pair< KEY, MAPPED_TYPE > >(const typename std::iterator_traits< INPUT_IT >::value_type &)> MapFunc
Definition: quantum_functions.h:37
Parallel execution engine used to run coroutines or IO tasks asynchronously. This class is the main e...
Definition: quantum_dispatcher.h:34
Interface to a task queue. For internal use only.
Definition: quantum_iqueue.h:33
Provides various counters related to queues and task execution.
Definition: quantum_queue_statistics.h:30
Definition: quantum_configuration.h:31
bool empty(IQueue::QueueType type=IQueue::QueueType::All, int queueId=(int) IQueue::QueueId::All) const
Check if the specified type and queue id is empty (i.e. there are no running tasks)
Definition: quantum_dispatcher_impl.h:228
int getNumCoroutineThreads() const
Returns the number of underlying coroutine threads as specified in the constructor....
Definition: quantum_dispatcher_impl.h:267
void resetStats()
Resets all coroutine and IO queue counters.
Definition: quantum_dispatcher_impl.h:292
Definition: quantum_icontext_base.h:26
std::function< std::pair< KEY, REDUCED_TYPE >(std::pair< KEY, std::vector< MAPPED_TYPE > > &&)> ReduceFunc
Definition: quantum_functions.h:40
ThreadContextPtr< std::vector< RET > > forEach(INPUT_IT first, INPUT_IT last, Functions::ForEachFunc< RET, INPUT_IT > func)
Applies the given unary function to all the elements in the range [first,last). This function runs in...
Definition: quantum_dispatcher_impl.h:106
typename IThreadFuture< T >::Ptr ThreadFuturePtr
Definition: quantum_ithread_future.h:69
int getNumIoThreads() const
Returns the number of underlying IO threads as specified in the constructor.
Definition: quantum_dispatcher_impl.h:273
const std::pair< int, int > & getCoroQueueIdRangeForAny() const
Gets the range [minQueueId, maxQueueId] of coroutine queueIds covered by IQueue::QueueId::Any when us...
Definition: quantum_dispatcher_impl.h:279
std::enable_if_t< std::is_convertible< typename std::iterator_traits< IT >::iterator_category, std::input_iterator_tag >::value > IsInputIterator
Definition: quantum_traits.h:62
Interface to a task. For internal use only.
Definition: quantum_itask.h:32
DEPRECATED Dispatcher(int numCoroutineThreads=-1, int numIoThreads=5, bool pinCoroutineThreadsToCores=false)
Constructor.
Definition: quantum_dispatcher_impl.h:28
typename IThreadContext< RET >::Ptr ThreadContextPtr
Definition: quantum_ithread_context.h:242
Configuration parameters for the Quantum library.
size_t size(IQueue::QueueType type=IQueue::QueueType::All, int queueId=(int) IQueue::QueueId::All) const
Returns the total number of queued tasks for the specified type and queue id.
Definition: quantum_dispatcher_impl.h:221