Commit 6ae2206d authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Let Baton methods be noexcept

Summary: [Folly] Let `Baton` methods be `noexcept`.

Reviewed By: djwatson

Differential Revision: D6508057

fbshipit-source-id: 2138a228d8291e79e9368cb77b0f63f4412524dc
parent 23e45679
...@@ -54,7 +54,7 @@ template < ...@@ -54,7 +54,7 @@ template <
template <typename> class Atom = std::atomic, template <typename> class Atom = std::atomic,
bool Blocking = true> // blocking vs spinning bool Blocking = true> // blocking vs spinning
struct Baton { struct Baton {
constexpr Baton() : state_(INIT) {} constexpr Baton() noexcept : state_(INIT) {}
Baton(Baton const&) = delete; Baton(Baton const&) = delete;
Baton& operator=(Baton const&) = delete; Baton& operator=(Baton const&) = delete;
...@@ -62,7 +62,7 @@ struct Baton { ...@@ -62,7 +62,7 @@ struct Baton {
/// It is an error to destroy a Baton on which a thread is currently /// 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 /// wait()ing. In practice this means that the waiter usually takes
/// responsibility for destroying the Baton. /// responsibility for destroying the Baton.
~Baton() { ~Baton() noexcept {
// The docblock for this function says that it can't be called when // 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 // there is a concurrent waiter. We assume a strong version of this
// requirement in which the caller must _know_ that this is true, they // requirement in which the caller must _know_ that this is true, they
...@@ -82,7 +82,7 @@ struct Baton { ...@@ -82,7 +82,7 @@ struct Baton {
/// Equivalent to destroying the Baton and creating a new one. It is /// 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 /// a bug to call this while there is a waiting thread, so in practice
/// the waiter will be the one that resets the baton. /// 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 // See ~Baton for a discussion about why relaxed is okay here
assert(state_.load(std::memory_order_relaxed) != WAITING); assert(state_.load(std::memory_order_relaxed) != WAITING);
...@@ -109,7 +109,7 @@ struct Baton { ...@@ -109,7 +109,7 @@ struct Baton {
/// lifetime starts at construction or reset() and ends at /// lifetime starts at construction or reset() and ends at
/// destruction or reset()) there can be at most one call to post(), /// destruction or reset()) there can be at most one call to post(),
/// in the single poster version. Any thread may call post(). /// in the single poster version. Any thread may call post().
void post() { void post() noexcept {
if (!Blocking) { if (!Blocking) {
/// Non-blocking version /// Non-blocking version
/// ///
...@@ -156,7 +156,7 @@ struct Baton { ...@@ -156,7 +156,7 @@ struct Baton {
/// could be relaxed somewhat without any perf or size regressions, /// could be relaxed somewhat without any perf or size regressions,
/// but by making this condition very restrictive we can provide better /// but by making this condition very restrictive we can provide better
/// checking in debug builds. /// checking in debug builds.
FOLLY_ALWAYS_INLINE void wait() { FOLLY_ALWAYS_INLINE void wait() noexcept {
if (try_wait()) { if (try_wait()) {
return; return;
} }
...@@ -175,7 +175,7 @@ struct Baton { ...@@ -175,7 +175,7 @@ struct Baton {
/// call wait, try_wait or timed_wait on the same baton without resetting /// call wait, try_wait or timed_wait on the same baton without resetting
/// ///
/// @return true if baton has been posted, false othewise /// @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); auto s = state_.load(std::memory_order_acquire);
assert(s == INIT || s == EARLY_DELIVERY); assert(s == INIT || s == EARLY_DELIVERY);
return LIKELY(s == EARLY_DELIVERY); return LIKELY(s == EARLY_DELIVERY);
...@@ -194,7 +194,7 @@ struct Baton { ...@@ -194,7 +194,7 @@ struct Baton {
/// false otherwise /// false otherwise
template <typename Rep, typename Period> template <typename Rep, typename Period>
FOLLY_ALWAYS_INLINE bool try_wait_for( FOLLY_ALWAYS_INLINE bool try_wait_for(
const std::chrono::duration<Rep, Period>& timeout) { const std::chrono::duration<Rep, Period>& timeout) noexcept {
static_assert( static_assert(
Blocking, "Non-blocking Baton does not support try_wait_for."); Blocking, "Non-blocking Baton does not support try_wait_for.");
...@@ -219,7 +219,7 @@ struct Baton { ...@@ -219,7 +219,7 @@ struct Baton {
/// false otherwise /// false otherwise
template <typename Clock, typename Duration> template <typename Clock, typename Duration>
FOLLY_ALWAYS_INLINE bool try_wait_until( FOLLY_ALWAYS_INLINE bool try_wait_until(
const std::chrono::time_point<Clock, Duration>& deadline) { const std::chrono::time_point<Clock, Duration>& deadline) noexcept {
static_assert( static_assert(
Blocking, "Non-blocking Baton does not support try_wait_until."); Blocking, "Non-blocking Baton does not support try_wait_until.");
...@@ -233,14 +233,14 @@ struct Baton { ...@@ -233,14 +233,14 @@ struct Baton {
/// Alias to try_wait_for. Deprecated. /// Alias to try_wait_for. Deprecated.
template <typename Rep, typename Period> template <typename Rep, typename Period>
FOLLY_ALWAYS_INLINE bool timed_wait( FOLLY_ALWAYS_INLINE bool timed_wait(
const std::chrono::duration<Rep, Period>& timeout) { const std::chrono::duration<Rep, Period>& timeout) noexcept {
return try_wait_for(timeout); return try_wait_for(timeout);
} }
/// Alias to try_wait_until. Deprecated. /// Alias to try_wait_until. Deprecated.
template <typename Clock, typename Duration> template <typename Clock, typename Duration>
FOLLY_ALWAYS_INLINE bool timed_wait( FOLLY_ALWAYS_INLINE bool timed_wait(
const std::chrono::time_point<Clock, Duration>& deadline) { const std::chrono::time_point<Clock, Duration>& deadline) noexcept {
return try_wait_until(deadline); return try_wait_until(deadline);
} }
...@@ -276,7 +276,7 @@ struct Baton { ...@@ -276,7 +276,7 @@ struct Baton {
// @return true if we received an early delivery during the wait, // @return true if we received an early delivery during the wait,
// false otherwise. If the function returns true then // false otherwise. If the function returns true then
// state_ is guaranteed to be EARLY_DELIVERY // state_ is guaranteed to be EARLY_DELIVERY
bool spinWaitForEarlyDelivery() { bool spinWaitForEarlyDelivery() noexcept {
static_assert( static_assert(
PreBlockAttempts > 0, PreBlockAttempts > 0,
"isn't this assert clearer than an uninitialized variable warning?"); "isn't this assert clearer than an uninitialized variable warning?");
...@@ -295,7 +295,7 @@ struct Baton { ...@@ -295,7 +295,7 @@ struct Baton {
return false; return false;
} }
FOLLY_NOINLINE void waitSlow() { FOLLY_NOINLINE void waitSlow() noexcept {
if (spinWaitForEarlyDelivery()) { if (spinWaitForEarlyDelivery()) {
assert(state_.load(std::memory_order_acquire) == EARLY_DELIVERY); assert(state_.load(std::memory_order_acquire) == EARLY_DELIVERY);
return; return;
...@@ -348,7 +348,7 @@ struct Baton { ...@@ -348,7 +348,7 @@ struct Baton {
template <typename Clock, typename Duration> template <typename Clock, typename Duration>
FOLLY_NOINLINE bool tryWaitUntilSlow( FOLLY_NOINLINE bool tryWaitUntilSlow(
const std::chrono::time_point<Clock, Duration>& deadline) { const std::chrono::time_point<Clock, Duration>& deadline) noexcept {
if (spinWaitForEarlyDelivery()) { if (spinWaitForEarlyDelivery()) {
assert(state_.load(std::memory_order_acquire) == EARLY_DELIVERY); assert(state_.load(std::memory_order_acquire) == EARLY_DELIVERY);
return true; return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment