From ce7a59fb568011d5bd4172596db6fcf74c6fba82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 31 Aug 2018 07:37:50 +0300 Subject: [PATCH] Allow mxs::rworker_local By removing the constness of the type for the actual stored value, the return values of the access operators are defined by the type itself. This allows both const and non-const types to be stored in a rworker_local object. --- include/maxscale/routingworker.hh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/include/maxscale/routingworker.hh b/include/maxscale/routingworker.hh index b8dda0e64..43ca156d6 100644 --- a/include/maxscale/routingworker.hh +++ b/include/maxscale/routingworker.hh @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -462,14 +463,14 @@ public: mxs_rworker_delete_data(m_handle); } - // Converts to a const T reference - operator const T&() const + // Converts to a T reference + operator T&() const { return *get_local_value(); } // Arrow operator - const T* operator->() const + T* operator->() const { return get_local_value(); } @@ -494,9 +495,9 @@ public: private: - uint64_t m_handle; - mutable std::mutex m_lock; - T m_value; // The "master" value, never used directly + uint64_t m_handle; // The handle to the worker local data + typename std::remove_const::type m_value; // The master value, never used directly + mutable std::mutex m_lock; // Protects the master value private: