From 5e100ff128fe5baf01a88e62b28208b105561116 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 28 Mar 2018 19:30:28 -0600 Subject: [PATCH] Enable writing Threads::Thread for types T that are only movable. Previously, it was not possible to write Threads::new_thread(&foo) or Threads::new_task(&foo) for functions that return an object whose type is not copyable, but is movable. That's because in a number of places in the internal machinery of the Threads::Thread and Threads::Task classes, we didn't account for such types. This patch fixes this. --- include/deal.II/base/thread_management.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/include/deal.II/base/thread_management.h b/include/deal.II/base/thread_management.h index 006f89fdbb..ed332ba1bd 100644 --- a/include/deal.II/base/thread_management.h +++ b/include/deal.II/base/thread_management.h @@ -692,16 +692,18 @@ namespace Threads private: RT value; public: + typedef RT &reference_type; + inline return_value () : value() {} - inline RT get () const + inline reference_type get () { return value; } - inline void set (RT v) + inline void set (RT &&v) { - value = v; + value = std::move(v); } }; @@ -720,14 +722,17 @@ namespace Threads private: RT *value; public: + typedef RT &reference_type; + inline return_value () : value(nullptr) {} - inline RT &get () const + inline reference_type get () const { return *value; } + inline void set (RT &v) { value = &v; @@ -745,6 +750,8 @@ namespace Threads */ template <> struct return_value { + typedef void reference_type; + static inline void get () {} }; } @@ -1025,7 +1032,8 @@ namespace Threads * Get the return value of the function of the thread. Since this is only * available once the thread finishes, this implicitly also calls join(). */ - RT return_value () + typename internal::return_value::reference_type + return_value () { join (); return thread_descriptor->ret_val->get(); @@ -1702,7 +1710,7 @@ namespace Threads * constructor of this class and have not assigned a task object to it. In * other words, the function joinable() must return true. */ - RT return_value () + typename internal::return_value::reference_type return_value () { join (); return task_descriptor->ret_val.get(); -- 2.39.5