15#ifndef dealii_task_result_h
16#define dealii_task_result_h
124 std::is_move_constructible_v<T> &&std::is_move_assignable_v<T>);
200 std::is_move_constructible_v<T> &&std::is_move_assignable_v<T>);
319 template <
typename Callable>
336 std::is_copy_assignable_v<T>));
350 std::is_copy_assignable_v<T>));
408 mutable std::optional<Task<T>>
task;
426 template <
typename T>
429 std::is_move_constructible_v<T> &&std::is_move_assignable_v<T>)
434 std::lock_guard<std::mutex> lock(other.mutex);
436 result_is_available = other.result_is_available.load();
437 other.result_is_available =
false;
439 task = std::move(other.task);
442 task_result = std::move(other.task_result);
443 other.task_result.reset();
448 template <
typename T>
459 template <
typename T>
471 std::lock_guard<std::mutex> lock(mutex);
477 template <
typename T>
478 inline TaskResult<T> &
481 std::is_move_constructible_v<T> &&std::is_move_assignable_v<T>)
490 std::lock_guard<std::mutex> lock(other.mutex);
492 result_is_available = other.result_is_available.load();
493 other.result_is_available =
false;
495 task = std::move(other.task);
498 task_result = std::move(other.task_result);
499 other.task_result.reset();
506 template <
typename T>
507 template <
typename Callable>
513 if (result_is_available)
520 std::lock_guard<std::mutex> lock(mutex);
521 if (result_is_available)
526 if (task.has_value())
536 template <
typename T>
540 std::is_copy_assignable_v<T>))
544 result_is_available =
true;
548 template <
typename T>
552 std::is_copy_assignable_v<T>))
555 task_result = std::move(t);
556 result_is_available =
true;
560 template <
typename T>
564 std::lock_guard<std::mutex> lock(mutex);
566 if (result_is_available)
570 result_is_available =
false;
574 Assert(task.has_value() ==
false,
575 ExcMessage(
"You cannot destroy a TaskResult object "
576 "while it is still waiting for its associated task "
577 "to finish. See the documentation of this class' "
578 "destructor for more information."));
583 template <
typename T>
588 ExcMessage(
"You can't join a TaskResult object that has not "
589 "been associated with a task."));
592 if (result_is_available)
601 std::lock_guard<std::mutex> lock(mutex);
602 if (result_is_available)
611 task_result = std::move(task.value().return_value());
614 result_is_available =
true;
621 template <
typename T>
626 if (result_is_available)
631 else if (task.has_value())
642 std::lock_guard<std::mutex> lock(mutex);
643 if (result_is_available)
657 template <
typename T>
663 "You can't ask for the result of a TaskResult object that "
664 "has not been associated with a task."));
666 if (!result_is_available)
668 return task_result.value();
TaskResult & operator=(TaskResult &&other) noexcept
void emplace_object(const T &t)
void operator=(const Task< T > &t)
TaskResult(const TaskResult< T > &)=delete
TaskResult(TaskResult< T > &&other) noexcept
TaskResult & operator=(const TaskResult &)=delete
std::optional< Task< T > > task
std::optional< T > task_result
void emplace_object(T &&t)
TaskResult(const Task< T > &task)
void try_emplace_task(const Callable &creator) const
std::atomic< bool > result_is_available
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
Task< RT > new_task(const std::function< RT()> &function)