16#ifndef dealii_task_result_h
17#define dealii_task_result_h
125 std::is_move_constructible_v<T> &&std::is_move_assignable_v<T>);
201 std::is_move_constructible_v<T> &&std::is_move_assignable_v<T>);
320 template <
typename Callable>
337 std::is_copy_assignable_v<T>));
351 std::is_copy_assignable_v<T>));
409 mutable std::optional<Task<T>>
task;
427 template <
typename T>
430 std::is_move_constructible_v<T> &&std::is_move_assignable_v<T>)
435 std::lock_guard<std::mutex> lock(other.mutex);
437 result_is_available = other.result_is_available.load();
438 other.result_is_available =
false;
440 task = std::move(other.task);
443 task_result = std::move(other.task_result);
444 other.task_result.reset();
449 template <
typename T>
460 template <
typename T>
472 std::lock_guard<std::mutex> lock(mutex);
478 template <
typename T>
479 inline TaskResult<T> &
482 std::is_move_constructible_v<T> &&std::is_move_assignable_v<T>)
491 std::lock_guard<std::mutex> lock(other.mutex);
493 result_is_available = other.result_is_available.load();
494 other.result_is_available =
false;
496 task = std::move(other.task);
499 task_result = std::move(other.task_result);
500 other.task_result.reset();
507 template <
typename T>
508 template <
typename Callable>
514 if (result_is_available)
521 std::lock_guard<std::mutex> lock(mutex);
522 if (result_is_available)
527 if (task.has_value())
537 template <
typename T>
541 std::is_copy_assignable_v<T>))
545 result_is_available =
true;
549 template <
typename T>
553 std::is_copy_assignable_v<T>))
556 task_result = std::move(t);
557 result_is_available =
true;
561 template <
typename T>
565 std::lock_guard<std::mutex> lock(mutex);
567 if (result_is_available)
571 result_is_available =
false;
575 Assert(task.has_value() ==
false,
576 ExcMessage(
"You cannot destroy a TaskResult object "
577 "while it is still waiting for its associated task "
578 "to finish. See the documentation of this class' "
579 "destructor for more information."));
584 template <
typename T>
589 ExcMessage(
"You can't join a TaskResult object that has not "
590 "been associated with a task."));
593 if (result_is_available)
602 std::lock_guard<std::mutex> lock(mutex);
603 if (result_is_available)
612 task_result = std::move(task.value().return_value());
615 result_is_available =
true;
622 template <
typename T>
627 if (result_is_available)
632 else if (task.has_value())
643 std::lock_guard<std::mutex> lock(mutex);
644 if (result_is_available)
658 template <
typename T>
664 "You can't ask for the result of a TaskResult object that "
665 "has not been associated with a task."));
667 if (!result_is_available)
669 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)