From 674533ad47f61e0151bc298869fa7696c8147c94 Mon Sep 17 00:00:00 2001 From: Alan Frindell Date: Wed, 5 Apr 2017 16:37:16 -0700 Subject: [PATCH] Make NotificationQueue::Consumer::messageAvailable noexcept Summary: There's a comment in that code that states that it *it* noexcept, and that is common for most folly async io callbacks. Reviewed By: yfeldblum Differential Revision: D4831800 fbshipit-source-id: 78894ad72504b9dfe540c14b8d7bbb29247aaf87 --- folly/io/async/AsyncServerSocket.cpp | 3 +-- folly/io/async/AsyncServerSocket.h | 2 +- folly/io/async/EventBase.cpp | 2 +- folly/io/async/NotificationQueue.h | 4 ++-- folly/io/async/test/NotificationQueueTest.cpp | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/folly/io/async/AsyncServerSocket.cpp b/folly/io/async/AsyncServerSocket.cpp index dc6b4b6c..7e02dde7 100644 --- a/folly/io/async/AsyncServerSocket.cpp +++ b/folly/io/async/AsyncServerSocket.cpp @@ -90,8 +90,7 @@ void AsyncServerSocket::RemoteAcceptor::stop( } void AsyncServerSocket::RemoteAcceptor::messageAvailable( - QueueMessage&& msg) { - + QueueMessage&& msg) noexcept { switch (msg.type) { case MessageType::MSG_NEW_CONN: { diff --git a/folly/io/async/AsyncServerSocket.h b/folly/io/async/AsyncServerSocket.h index f509cbc6..63ca06ed 100644 --- a/folly/io/async/AsyncServerSocket.h +++ b/folly/io/async/AsyncServerSocket.h @@ -755,7 +755,7 @@ class AsyncServerSocket : public DelayedDestruction void start(EventBase *eventBase, uint32_t maxAtOnce, uint32_t maxInQueue); void stop(EventBase* eventBase, AcceptCallback* callback); - virtual void messageAvailable(QueueMessage&& message); + virtual void messageAvailable(QueueMessage&& message) noexcept override; NotificationQueue* getQueue() { return &queue_; diff --git a/folly/io/async/EventBase.cpp b/folly/io/async/EventBase.cpp index 1f5ea560..895e1a49 100644 --- a/folly/io/async/EventBase.cpp +++ b/folly/io/async/EventBase.cpp @@ -40,7 +40,7 @@ namespace folly { class EventBase::FunctionRunner : public NotificationQueue::Consumer { public: - void messageAvailable(Func&& msg) override { + void messageAvailable(Func&& msg) noexcept override { // In libevent2, internal events do not break the loop. // Most users would expect loop(), followed by runInEventBaseThread(), // to break the loop and check if it should exit or not. diff --git a/folly/io/async/NotificationQueue.h b/folly/io/async/NotificationQueue.h index f27b17f5..28a2878e 100644 --- a/folly/io/async/NotificationQueue.h +++ b/folly/io/async/NotificationQueue.h @@ -88,7 +88,7 @@ class NotificationQueue { * messageAvailable() will be invoked whenever a new * message is available from the pipe. */ - virtual void messageAvailable(MessageT&& message) = 0; + virtual void messageAvailable(MessageT&& message) noexcept = 0; /** * Begin consuming messages from the specified queue. @@ -855,7 +855,7 @@ struct notification_queue_consumer_wrapper : callback_(std::forward(callback)) {} // we are being stricter here and requiring noexcept for callback - void messageAvailable(MessageT&& message) override { + void messageAvailable(MessageT&& message) noexcept override { static_assert( noexcept(std::declval()(std::forward(message))), "callback must be declared noexcept, e.g.: `[]() noexcept {}`" diff --git a/folly/io/async/test/NotificationQueueTest.cpp b/folly/io/async/test/NotificationQueueTest.cpp index 465da1d3..7e5d9827 100644 --- a/folly/io/async/test/NotificationQueueTest.cpp +++ b/folly/io/async/test/NotificationQueueTest.cpp @@ -38,7 +38,7 @@ class QueueConsumer : public IntQueue::Consumer { public: QueueConsumer() {} - void messageAvailable(int&& value) override { + void messageAvailable(int&& value) noexcept override { messages.push_back(value); if (fn) { fn(value); @@ -360,7 +360,7 @@ void QueueTest::destroyCallback() { // avoid destroying the function object. class DestroyTestConsumer : public IntQueue::Consumer { public: - void messageAvailable(int&& value) override { + void messageAvailable(int&& value) noexcept override { DestructorGuard g(this); if (fn && *fn) { (*fn)(value); -- 2.34.1