]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Obey the rule of 5 or 7.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 23 Jul 2024 22:27:40 +0000 (16:27 -0600)
committerMatthias Maier <tamiko@43-1.org>
Thu, 25 Jul 2024 07:32:02 +0000 (02:32 -0500)
include/deal.II/base/task_result.h

index fa62e99f0aaa30350379c8f0d8d0fb345fc8f7a6..54f706b7cf7a3934297ed6aba8f917d5b5d27672 100644 (file)
@@ -182,6 +182,22 @@ namespace Threads
      */
     ~TaskResult();
 
+    /**
+     * Copy operator. Like the copy constructor, this function is deleted
+     * because TaskResult corresponds to the output of a specific task,
+     * not a copy of that tasks's outcome.
+     */
+    TaskResult &
+    operator=(const TaskResult &) = delete;
+
+    /**
+     * Move assignment operator. Following this call, the newly created object
+     * represents the task's result, whereas the old object no longer
+     * represents anything and is left as if default-constructed.
+     */
+    TaskResult &
+    operator=(TaskResult &&);
+
     /**
      * Copy assignment operator from a Task object. By assigning the Task
      * object to the current object, the current object is set to represent
@@ -426,6 +442,33 @@ namespace Threads
   }
 
 
+  template <typename T>
+  inline TaskResult<T> &
+  TaskResult<T>::operator=(TaskResult<T> &&other)
+  {
+    // First clear the current object before we put new content into it:
+    clear();
+
+    // Then lock the other object and move the members of the other
+    // object, and finally reset it. Note that we do not have to wait for
+    // the other object's task to finish (nor should we): We may simply
+    // inherit the other object's task.
+    std::lock_guard<std::mutex> lock(other.mutex);
+
+    result_is_available       = other.result_is_available.load();
+    other.result_is_available = false;
+
+    task = std::move(other.task);
+    other.task.reset();
+
+    task_result = std::move(other.task_result);
+    other.task_result.reset();
+
+    return *this;
+  }
+
+
+
   template <typename T>
   template <typename Callable>
   void

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.