From 61426d08de3b6d54565d83d76662616e2aebc4fb Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 20 Jun 2019 17:51:32 -0700 Subject: [PATCH] wpiutil: Signal: make operator() const (#1721) This enables const-ness in uv::Handle ReportError() and Invoke() as well. --- wpiutil/src/main/native/include/wpi/Signal.h | 6 +++--- wpiutil/src/main/native/include/wpi/uv/Handle.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wpiutil/src/main/native/include/wpi/Signal.h b/wpiutil/src/main/native/include/wpi/Signal.h index 8ef89bd66d..c53a2aa5a0 100644 --- a/wpiutil/src/main/native/include/wpi/Signal.h +++ b/wpiutil/src/main/native/include/wpi/Signal.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -570,7 +570,7 @@ public: * @param a... arguments to emit */ template - void operator()(A && ... a) { + void operator()(A && ... a) const { lock_type lock(m_mutex); if (!m_block && m_func) m_func(std::forward(a)...); } @@ -799,7 +799,7 @@ private: private: std::function m_func; - Lockable m_mutex; + mutable Lockable m_mutex; std::atomic m_block; }; diff --git a/wpiutil/src/main/native/include/wpi/uv/Handle.h b/wpiutil/src/main/native/include/wpi/uv/Handle.h index 63a2e45d86..9d91d37671 100644 --- a/wpiutil/src/main/native/include/wpi/uv/Handle.h +++ b/wpiutil/src/main/native/include/wpi/uv/Handle.h @@ -235,7 +235,7 @@ class Handle : public std::enable_shared_from_this { * Report an error. * @param err Error code */ - void ReportError(int err) { error(Error(err)); } + void ReportError(int err) const { error(Error(err)); } protected: explicit Handle(uv_handle_t* uv_handle) : m_uv_handle{uv_handle} { @@ -250,7 +250,7 @@ class Handle : public std::enable_shared_from_this { static void DefaultFreeBuf(Buffer& buf); template - bool Invoke(F&& f, Args&&... args) { + bool Invoke(F&& f, Args&&... args) const { auto err = std::forward(f)(std::forward(args)...); if (err < 0) ReportError(err); return err == 0;