From: Yedidya Feldblum Date: Fri, 15 Dec 2017 04:59:51 +0000 (-0800) Subject: Let Baton methods be noexcept X-Git-Tag: v2017.12.18.00~10 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6ae2206d4a23d683877e33919a469abfdfc411e5;p=folly.git Let Baton methods be noexcept Summary: [Folly] Let `Baton` methods be `noexcept`. Reviewed By: djwatson Differential Revision: D6508057 fbshipit-source-id: 2138a228d8291e79e9368cb77b0f63f4412524dc --- diff --git a/folly/synchronization/Baton.h b/folly/synchronization/Baton.h index 96b34661..ff6b2978 100644 --- a/folly/synchronization/Baton.h +++ b/folly/synchronization/Baton.h @@ -54,7 +54,7 @@ template < template class Atom = std::atomic, bool Blocking = true> // blocking vs spinning struct Baton { - constexpr Baton() : state_(INIT) {} + constexpr Baton() noexcept : state_(INIT) {} Baton(Baton const&) = delete; Baton& operator=(Baton const&) = delete; @@ -62,7 +62,7 @@ struct Baton { /// It is an error to destroy a Baton on which a thread is currently /// wait()ing. In practice this means that the waiter usually takes /// responsibility for destroying the Baton. - ~Baton() { + ~Baton() noexcept { // The docblock for this function says that it can't be called when // there is a concurrent waiter. We assume a strong version of this // requirement in which the caller must _know_ that this is true, they @@ -82,7 +82,7 @@ struct Baton { /// Equivalent to destroying the Baton and creating a new one. It is /// a bug to call this while there is a waiting thread, so in practice /// the waiter will be the one that resets the baton. - void reset() { + void reset() noexcept { // See ~Baton for a discussion about why relaxed is okay here assert(state_.load(std::memory_order_relaxed) != WAITING); @@ -109,7 +109,7 @@ struct Baton { /// lifetime starts at construction or reset() and ends at /// destruction or reset()) there can be at most one call to post(), /// in the single poster version. Any thread may call post(). - void post() { + void post() noexcept { if (!Blocking) { /// Non-blocking version /// @@ -156,7 +156,7 @@ struct Baton { /// could be relaxed somewhat without any perf or size regressions, /// but by making this condition very restrictive we can provide better /// checking in debug builds. - FOLLY_ALWAYS_INLINE void wait() { + FOLLY_ALWAYS_INLINE void wait() noexcept { if (try_wait()) { return; } @@ -175,7 +175,7 @@ struct Baton { /// call wait, try_wait or timed_wait on the same baton without resetting /// /// @return true if baton has been posted, false othewise - FOLLY_ALWAYS_INLINE bool try_wait() const { + FOLLY_ALWAYS_INLINE bool try_wait() const noexcept { auto s = state_.load(std::memory_order_acquire); assert(s == INIT || s == EARLY_DELIVERY); return LIKELY(s == EARLY_DELIVERY); @@ -194,7 +194,7 @@ struct Baton { /// false otherwise template FOLLY_ALWAYS_INLINE bool try_wait_for( - const std::chrono::duration& timeout) { + const std::chrono::duration& timeout) noexcept { static_assert( Blocking, "Non-blocking Baton does not support try_wait_for."); @@ -219,7 +219,7 @@ struct Baton { /// false otherwise template FOLLY_ALWAYS_INLINE bool try_wait_until( - const std::chrono::time_point& deadline) { + const std::chrono::time_point& deadline) noexcept { static_assert( Blocking, "Non-blocking Baton does not support try_wait_until."); @@ -233,14 +233,14 @@ struct Baton { /// Alias to try_wait_for. Deprecated. template FOLLY_ALWAYS_INLINE bool timed_wait( - const std::chrono::duration& timeout) { + const std::chrono::duration& timeout) noexcept { return try_wait_for(timeout); } /// Alias to try_wait_until. Deprecated. template FOLLY_ALWAYS_INLINE bool timed_wait( - const std::chrono::time_point& deadline) { + const std::chrono::time_point& deadline) noexcept { return try_wait_until(deadline); } @@ -276,7 +276,7 @@ struct Baton { // @return true if we received an early delivery during the wait, // false otherwise. If the function returns true then // state_ is guaranteed to be EARLY_DELIVERY - bool spinWaitForEarlyDelivery() { + bool spinWaitForEarlyDelivery() noexcept { static_assert( PreBlockAttempts > 0, "isn't this assert clearer than an uninitialized variable warning?"); @@ -295,7 +295,7 @@ struct Baton { return false; } - FOLLY_NOINLINE void waitSlow() { + FOLLY_NOINLINE void waitSlow() noexcept { if (spinWaitForEarlyDelivery()) { assert(state_.load(std::memory_order_acquire) == EARLY_DELIVERY); return; @@ -348,7 +348,7 @@ struct Baton { template FOLLY_NOINLINE bool tryWaitUntilSlow( - const std::chrono::time_point& deadline) { + const std::chrono::time_point& deadline) noexcept { if (spinWaitForEarlyDelivery()) { assert(state_.load(std::memory_order_acquire) == EARLY_DELIVERY); return true;