16 #ifndef ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_THREADING_EXECUTOR_H_ 17 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_THREADING_EXECUTOR_H_ 20 #include <condition_variable> 59 Executor(
const std::chrono::milliseconds& unused) noexcept;
74 bool execute(std::function<
void()>&&
function) noexcept;
84 bool execute(
const std::function<
void()>&
function) noexcept;
100 template <
typename Task,
typename...
Args>
101 auto submit(Task task,
Args&&...
args) noexcept -> std::future<decltype(task(
args...))>;
118 template <
typename Task,
typename...
Args>
137 operator std::shared_ptr<ExecutorInterface>()
const noexcept;
146 enum class QueuePosition {
163 bool execute(std::function<
void()>&&
function, QueuePosition queuePosition) noexcept;
175 template <
typename Task,
typename...
Args>
176 auto pushTo(QueuePosition queuePosition, Task&& task,
Args&&...
args) noexcept
177 -> std::future<decltype(task(
args...))>;
189 template <
typename T>
190 std::future<T> pushFunction(QueuePosition queuePosition, std::function<T()>&&
function) noexcept;
199 template <
typename Task,
typename...
Args>
201 return pushTo(QueuePosition::Back, std::forward<Task>(task), std::forward<Args>(
args)...);
204 template <
typename Task,
typename...
Args>
206 return pushTo(QueuePosition::Front, std::forward<Task>(task), std::forward<Args>(
args)...);
215 template <
typename T>
216 inline static void forwardPromise(std::promise<T>& promise, std::future<T>& future) noexcept {
217 #if __cpp_exceptions || defined(__EXCEPTIONS) 220 promise.set_value(future.get());
221 #if __cpp_exceptions || defined(__EXCEPTIONS) 223 promise.set_exception(std::current_exception());
236 #if __cpp_exceptions || defined(__EXCEPTIONS) 241 #if __cpp_exceptions || defined(__EXCEPTIONS) 243 promise.set_exception(std::current_exception());
248 template <
typename Task,
typename...
Args>
249 inline auto Executor::pushTo(QueuePosition queuePosition, Task&& task,
Args&&...
args) noexcept
250 -> std::future<decltype(task(
args...))> {
251 using ValueType = decltype(task(
args...));
253 std::function<ValueType()> fn{std::bind(std::forward<Task>(task), std::forward<Args>(
args)...)};
254 return pushFunction(queuePosition,
std::move(fn));
257 template <
typename T>
258 std::future<T> Executor::pushFunction(QueuePosition queuePosition, std::function<T()>&&
function) noexcept {
282 inline CallCtx(std::function<T()>&&
function) : packagedTask{
std::move(
function)} {
286 std::packaged_task<T()> packagedTask;
288 std::promise<T> cleanupPromise;
291 auto callCtx = std::make_shared<CallCtx>(
std::move(
function));
294 auto translated_task = [callCtx]()
mutable {
296 callCtx->packagedTask();
298 auto taskFuture = callCtx->packagedTask.get_future();
300 callCtx->packagedTask.reset();
301 auto cleanupPromise =
std::move(callCtx->cleanupPromise);
309 auto cleanupFuture = callCtx->cleanupPromise.get_future();
315 return std::future<T>();
318 return cleanupFuture;
323 extern template std::future<void> Executor::pushFunction(
324 QueuePosition queuePosition,
325 std::function<
void()>&&
function) noexcept;
326 extern template std::future<bool> Executor::pushFunction(
327 QueuePosition queuePosition,
328 std::function<
bool()>&&
function) noexcept;
329 extern template std::future<std::string> Executor::pushFunction(
330 QueuePosition queuePosition,
339 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_THREADING_EXECUTOR_H_ def args
Definition: android_test.py:111
bool execute(std::function< void()> &&function) noexcept
Schedules a function for execution.
::std::string string
Definition: gtest-port.h:1097
Single-thread executor implementation.
Definition: Executor.h:45
Definition: CapabilityConfiguration.h:190
auto submit(Task task, Args &&... args) noexcept -> std::future< decltype(task(args...))>
Definition: Executor.h:200
bool isShutdown() noexcept
Returns whether or not the executor is shutdown.
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
Definition: gmock-generated-matchers.h:481
auto submitToFront(Task task, Args &&... args) noexcept -> std::future< decltype(task(args...))>
Definition: Executor.h:205
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
friend class SharedExecutor
Definition: Executor.h:141
void forwardPromise< void >(std::promise< void > &promise, std::future< void > &future) noexcept
Definition: Executor.h:235
const
Definition: upload.py:398
static void forwardPromise(std::promise< T > &promise, std::future< T > &future) noexcept
Definition: Executor.h:216
const T & move(const T &t)
Definition: gtest-port.h:1317
void shutdown() noexcept
Clears the executor of outstanding tasks and refuses any additional tasks to be submitted.
void waitForSubmittedTasks() noexcept