From a91971707da2903e1d28a58ac18ae369df7fbf53 Mon Sep 17 00:00:00 2001 From: Maged Michael Date: Thu, 7 Dec 2017 14:41:53 -0800 Subject: [PATCH] FlatCombining: Use SaturatingSemaphore instead of multi-poster and non-blocking Baton Summary: Use SaturatingSemaphore instead of multi-poster and non-blocking Baton, in preparation for restoring Baton to being single-poster and with blocking wait(). Reviewed By: davidtgoldblatt Differential Revision: D6510619 fbshipit-source-id: eed87beabc1b698080b8e41c746d570d30804ce7 --- .../flat_combining/FlatCombining.h | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/folly/experimental/flat_combining/FlatCombining.h b/folly/experimental/flat_combining/FlatCombining.h index 235e24b2..bf19e235 100644 --- a/folly/experimental/flat_combining/FlatCombining.h +++ b/folly/experimental/flat_combining/FlatCombining.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2017-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +20,12 @@ #include #include #include -#include +#include #include #include #include +#include namespace folly { @@ -112,9 +113,9 @@ class FlatCombining { /// Combining request record. class Rec { FOLLY_ALIGN_TO_AVOID_FALSE_SHARING - folly::Baton valid_; - folly::Baton done_; - folly::Baton disconnected_; + folly::SaturatingSemaphore valid_; + folly::SaturatingSemaphore done_; + folly::SaturatingSemaphore disconnected_; size_t index_; size_t next_; uint64_t last_; @@ -136,7 +137,7 @@ class FlatCombining { } bool isValid() const { - return valid_.try_wait(); + return valid_.ready(); } void setDone() { @@ -148,7 +149,7 @@ class FlatCombining { } bool isDone() const { - return done_.try_wait(); + return done_.ready(); } void awaitDone() { @@ -164,7 +165,7 @@ class FlatCombining { } bool isDisconnected() const { - return disconnected_.try_wait(); + return disconnected_.ready(); } void setIndex(const size_t index) { @@ -424,7 +425,7 @@ class FlatCombining { Mutex m_; FOLLY_ALIGN_TO_AVOID_FALSE_SHARING - folly::Baton pending_; + folly::SaturatingSemaphore pending_; Atom shutdown_{false}; FOLLY_ALIGN_TO_AVOID_FALSE_SHARING @@ -541,7 +542,7 @@ class FlatCombining { } bool isPending() const { - return pending_.try_wait(); + return pending_.ready(); } void awaitPending() { -- 2.34.1