dispenso
A library for task parallelism
 
Loading...
Searching...
No Matches
future.h File Reference
#include <functional>
#include <vector>
#include <dispenso/detail/future_impl.h>
#include <dispenso/detail/result_of.h>
#include <dispenso/schedulable.h>
#include <dispenso/detail/future_impl2.h>

Go to the source code of this file.

Classes

class  dispenso::Future< Result >
 
class  dispenso::Future< Result & >
 
class  dispenso::Future< void >
 

Functions

template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async (std::launch policy, F &&f, Args &&... args)
 
template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async (F &&f, Args &&... args)
 
template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async (ThreadPool &pool, std::launch policy, F &&f, Args &&... args)
 
template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async (ThreadPool &pool, F &&f, Args &&... args)
 
template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async (TaskSet &tasks, std::launch policy, F &&f, Args &&... args)
 
template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async (TaskSet &tasks, F &&f, Args &&... args)
 
template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async (ConcurrentTaskSet &tasks, std::launch policy, F &&f, Args &&... args)
 
template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async (ConcurrentTaskSet &tasks, F &&f, Args &&... args)
 
template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async (NewThreadInvoker sched, std::launch policy, F &&f, Args &&... args)
 
template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async (NewThreadInvoker sched, F &&f, Args &&... args)
 
template<typename T >
Future< std::decay_t< T > > dispenso::make_ready_future (T &&t)
 
template<typename X >
Future< X & > dispenso::make_ready_future (std::reference_wrapper< X > x)
 
Future< voiddispenso::make_ready_future ()
 
template<class InputIt >
Future< std::vector< typename std::iterator_traits< InputIt >::value_type > > dispenso::when_all (InputIt first, InputIt last)
 
template<class... Futures>
auto dispenso::when_all (Futures &&... futures) -> Future< std::tuple< std::decay_t< Futures >... > >
 
template<class InputIt >
Future< std::vector< typename std::iterator_traits< InputIt >::value_type > > dispenso::when_all (TaskSet &taskSet, InputIt first, InputIt last)
 
template<class InputIt >
Future< std::vector< typename std::iterator_traits< InputIt >::value_type > > dispenso::when_all (ConcurrentTaskSet &taskSet, InputIt first, InputIt last)
 
template<class... Futures>
auto dispenso::when_all (TaskSet &taskSet, Futures &&... futures) -> Future< std::tuple< std::decay_t< Futures >... > >
 
template<class... Futures>
auto dispenso::when_all (ConcurrentTaskSet &taskSet, Futures &&... futures) -> Future< std::tuple< std::decay_t< Futures >... > >
 

Variables

constexpr std::launch dispenso::kNotAsync = static_cast<std::launch>(0)
 
constexpr std::launch dispenso::kNotDeferred = static_cast<std::launch>(0)
 

Detailed Description

A file providing Futures, as well as functionality for creating futures, and for how to invoke Futures' closures.

See https://en.cppreference.com/w/cpp/experimental/future for details on the API.

Definition in file future.h.

Function Documentation

◆ async() [1/10]

template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async ( ConcurrentTaskSet tasks,
F &&  f,
Args &&...  args 
)
inline

Invoke a functor through the specified dispenso ConcurrentTaskSet.

Parameters
tasksThe ConcurrentTaskSet to run the Future.
fThe functor to be passed, or a function to be executed
argsThe remaining arguments that will be passed to f

Definition at line 533 of file future.h.

◆ async() [2/10]

template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async ( ConcurrentTaskSet tasks,
std::launch  policy,
F &&  f,
Args &&...  args 
)
inline

Invoke a functor through the specified dispenso ConcurrentTaskSet.

Parameters
tasksThe ConcurrentTaskSet to run the Future.
policyThe bitmask policy for when/how the functor can be invoked. std::launch::async will result in the functor being forced onto a ThreadPool work queue. std::launch::deferred specifies that Future::wait_for and Future::wait_until may invoke the functor.
fThe functor to be passed, or a function to be executed
argsThe remaining arguments that will be passed to f

Definition at line 520 of file future.h.

◆ async() [3/10]

template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async ( F &&  f,
Args &&...  args 
)
inline

Invoke a functor through the global dispenso thread pool.

Parameters
fThe functor to be passed, or a function to be executed
argsThe remaining arguments that will be passed to f

Definition at line 441 of file future.h.

◆ async() [4/10]

template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async ( NewThreadInvoker  sched,
F &&  f,
Args &&...  args 
)
inline

Invoke a functor on a new thread.

Parameters
schedA NewThreadInvoker.
fThe functor to be passed, or a function to be executed
argsThe remaining arguments that will be passed to f

Definition at line 564 of file future.h.

◆ async() [5/10]

template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async ( NewThreadInvoker  sched,
std::launch  policy,
F &&  f,
Args &&...  args 
)
inline

Invoke a functor on a new thread.

Parameters
schedA NewThreadInvoker
policyThe bitmask policy for when/how the functor can be invoked. std::launch::async will result in the functor being forced onto a ThreadPool work queue. std::launch::deferred specifies that Future::wait_for and Future::wait_until may invoke the functor.
fThe functor to be passed, or a function to be executed
argsThe remaining arguments that will be passed to f

Definition at line 551 of file future.h.

◆ async() [6/10]

template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async ( std::launch  policy,
F &&  f,
Args &&...  args 
)
inline

Invoke a functor through the global dispenso thread pool.

Parameters
policyThe bitmask policy for when/how the functor can be invoked. std::launch::async will result in the functor being forced onto a ThreadPool work queue. std::launch::deferred specifies that Future::wait_for and Future::wait_until may invoke the functor.
fThe functor to be passed, or a function to be executed
argsThe remaining arguments that will be passed to f

Definition at line 429 of file future.h.

◆ async() [7/10]

template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async ( TaskSet tasks,
F &&  f,
Args &&...  args 
)
inline

Invoke a functor through the specified dispenso TaskSet.

Parameters
tasksThe TaskSet to run the Future.
fThe functor to be passed, or a function to be executed
argsThe remaining arguments that will be passed to f

Definition at line 502 of file future.h.

◆ async() [8/10]

template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async ( TaskSet tasks,
std::launch  policy,
F &&  f,
Args &&...  args 
)
inline

Invoke a functor through the specified dispenso TaskSet.

Parameters
tasksThe TaskSet to run the Future.
policyThe bitmask policy for when/how the functor can be invoked. std::launch::async will result in the functor being forced onto a ThreadPool work queue. std::launch::deferred specifies that Future::wait_for and Future::wait_until may invoke the functor.
fThe functor to be passed, or a function to be executed
argsThe remaining arguments that will be passed to f

Definition at line 489 of file future.h.

◆ async() [9/10]

template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async ( ThreadPool pool,
F &&  f,
Args &&...  args 
)
inline

Invoke a functor through the specified dispenso thread pool.

Parameters
poolThe ThreadPool to run the Future.
fThe functor to be passed, or a function to be executed
argsThe remaining arguments that will be passed to f

Definition at line 471 of file future.h.

◆ async() [10/10]

template<class F , class... Args>
Future< detail::ResultOf< F, Args... > > dispenso::async ( ThreadPool pool,
std::launch  policy,
F &&  f,
Args &&...  args 
)
inline

Invoke a functor through the specified dispenso thread pool.

Parameters
poolThe ThreadPool to run the Future.
policyThe bitmask policy for when/how the functor can be invoked. std::launch::async will result in the functor being forced onto a ThreadPool work queue. std::launch::deferred specifies that Future::wait_for and Future::wait_until may invoke the functor.
fThe functor to be passed, or a function to be executed
argsThe remaining arguments that will be passed to f

Definition at line 458 of file future.h.

◆ make_ready_future() [1/3]

Future< void > dispenso::make_ready_future ( )
inline

Make a Future<void> in a ready state.

Definition at line 595 of file future.h.

◆ make_ready_future() [2/3]

template<typename X >
Future< X & > dispenso::make_ready_future ( std::reference_wrapper< X x)
inline

Make a Future in a ready state with the reference_wrapper passed into make_ready_future

Parameters
xthe wrapped reference to use to create the returned future.

Definition at line 587 of file future.h.

◆ make_ready_future() [3/3]

template<typename T >
Future< std::decay_t< T > > dispenso::make_ready_future ( T &&  t)
inline

Make a Future in a ready state with the value passed into make_ready_future

Parameters
tthe value to use to create the returned future.

Definition at line 576 of file future.h.

◆ when_all() [1/4]

template<class... Futures>
auto dispenso::when_all ( Futures &&...  futures) -> Future< std::tuple< std::decay_t< Futures >... > >

Take a specific set of futures, and return a future which will be ready when all input futures are ready.

Parameters
futuresA parameter pack of futures.
Returns
A Future containing a tuple holding copies of the input Futures. The returned Future will be in ready state when all input Futures are ready.

◆ when_all() [2/4]

template<class InputIt >
Future< std::vector< typename std::iterator_traits< InputIt >::value_type > > dispenso::when_all ( InputIt  first,
InputIt  last 
)

Take a collection of futures, and return a future which will be ready when all input futures are ready.

Parameters
firstAn iterator to the start of the future collection.
lastAn iterator to the end of the future collection.
Returns
A Future containing a vector holding copies of the input Futures. The returned Future will be in ready state when all input Futures are ready.

◆ when_all() [3/4]

template<class... Futures>
auto dispenso::when_all ( TaskSet taskSet,
Futures &&...  futures 
) -> Future< std::tuple< std::decay_t< Futures >... > >

Take a specific set of futures, and return a future which will be ready when all input futures are ready.

Parameters
tastSetA task set to register with such that after this call, taskSet::wait() implies that the resultant future is_ready()
futuresA parameter pack of futures.
Returns
A Future containing a tuple holding copies of the input Futures. The returned Future will be in ready state when all input Futures are ready.

◆ when_all() [4/4]

template<class InputIt >
Future< std::vector< typename std::iterator_traits< InputIt >::value_type > > dispenso::when_all ( TaskSet taskSet,
InputIt  first,
InputIt  last 
)

Take a collection of futures, and return a future which will be ready when all input futures are ready.

Parameters
tastSetA task set to register with such that after this call, taskSet::wait() implies that the resultant future is_ready()
firstAn iterator to the start of the future collection.
lastAn iterator to the end of the future collection.
Returns
A Future containing a vector holding copies of the input Futures. The returned Future will be in ready state when all input Futures are ready.

Variable Documentation

◆ kNotAsync

constexpr std::launch dispenso::kNotAsync = static_cast<std::launch>(0)
constexpr

A std::launch policy specifying we won't force asynchronicity. Opposite of std::launch::async

Definition at line 35 of file future.h.

◆ kNotDeferred

constexpr std::launch dispenso::kNotDeferred = static_cast<std::launch>(0)
constexpr

A std::launch policy specifying we won't allow Future::wait_for and Future::wait_util to invoke the Future's underlying functor. Opposite of std::launch::deferred

Definition at line 41 of file future.h.