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

Switch to the try_wait_for and try_wait_until Baton APIs

Summary: Switch to the `try_wait_for` and `try_wait_until` `Baton` APIs.

Reviewed By: davidtgoldblatt

Differential Revision: D6532103

fbshipit-source-id: aa3ce64152d167bb9c9cb1f266be0f9f8bd498f5
parent eb7bc45f
......@@ -155,8 +155,8 @@ void SingletonHolder<T>::destroyInstance() {
instance_copy_.reset();
if (destroy_baton_) {
constexpr std::chrono::seconds kDestroyWaitTime{5};
auto last_reference_released = destroy_baton_->timed_wait(
std::chrono::steady_clock::now() + kDestroyWaitTime);
auto last_reference_released =
destroy_baton_->try_wait_for(kDestroyWaitTime);
if (last_reference_released) {
teardown_(instance_ptr_);
} else {
......
......@@ -408,7 +408,7 @@ class SingletonVault {
* folly::IOThreadPoolExecutor executor(max_concurrency_level);
* folly::Baton<> done;
* doEagerInitVia(executor, &done);
* done.wait(); // or 'timed_wait', or spin with 'try_wait'
* done.wait(); // or 'try_wait_for', etc.
*
*/
void doEagerInitVia(Executor& exe, folly::Baton<>* done = nullptr);
......
......@@ -38,7 +38,7 @@ TEST(Observer, Observable) {
observable.setValue(24);
EXPECT_TRUE(baton.timed_wait(std::chrono::seconds{1}));
EXPECT_TRUE(baton.try_wait_for(std::chrono::seconds{1}));
EXPECT_EQ(24, **observer);
}
......@@ -62,7 +62,7 @@ TEST(Observer, MakeObserver) {
observable.setValue(24);
EXPECT_TRUE(baton.timed_wait(std::chrono::seconds{1}));
EXPECT_TRUE(baton.try_wait_for(std::chrono::seconds{1}));
EXPECT_EQ(25, **observer);
}
......@@ -93,7 +93,7 @@ TEST(Observer, MakeObserverDiamond) {
observable.setValue(24);
EXPECT_TRUE(baton.timed_wait(std::chrono::seconds{1}));
EXPECT_TRUE(baton.try_wait_for(std::chrono::seconds{1}));
EXPECT_EQ(25 * 26, **observer);
}
......@@ -136,14 +136,14 @@ TEST(Observer, NullValue) {
observable.setValue(2);
// Waiting observer shouldn't be updated
EXPECT_FALSE(baton.timed_wait(std::chrono::seconds{1}));
EXPECT_FALSE(baton.try_wait_for(std::chrono::seconds{1}));
baton.reset();
EXPECT_EQ(82, **oddObserver);
observable.setValue(23);
EXPECT_TRUE(baton.timed_wait(std::chrono::seconds{1}));
EXPECT_TRUE(baton.try_wait_for(std::chrono::seconds{1}));
EXPECT_EQ(46, **oddObserver);
}
......@@ -199,7 +199,7 @@ TEST(Observer, Cycle) {
for (size_t i = 1; i <= 3; ++i) {
observable.setValue(i);
EXPECT_TRUE(baton.timed_wait(std::chrono::seconds{1}));
EXPECT_TRUE(baton.try_wait_for(std::chrono::seconds{1}));
baton.reset();
EXPECT_EQ(i, **collectObserver);
......
......@@ -629,7 +629,7 @@ TEST(FunctionScheduler, CancelAndWaitOnRunningFunc) {
baton.post();
});
ASSERT_TRUE(baton.timed_wait(testInterval(15)));
ASSERT_TRUE(baton.try_wait_for(testInterval(15)));
th.join();
}
......@@ -644,7 +644,7 @@ TEST(FunctionScheduler, CancelAllAndWaitWithRunningFunc) {
baton.post();
});
ASSERT_TRUE(baton.timed_wait(testInterval(15)));
ASSERT_TRUE(baton.try_wait_for(testInterval(15)));
th.join();
}
......@@ -675,7 +675,7 @@ TEST(FunctionScheduler, CancelAllAndWaitWithOneRunningAndOneWaiting) {
baton.post();
});
ASSERT_TRUE(baton.timed_wait(testInterval(15)));
ASSERT_TRUE(baton.try_wait_for(testInterval(15)));
th.join();
}
......
......@@ -1379,7 +1379,7 @@ void waitImpl(FutureType& f, Duration dur) {
});
doBoost(f);
f = std::move(ret);
if (baton->timed_wait(dur)) {
if (baton->try_wait_for(dur)) {
assert(f.isReady());
}
}
......
......@@ -79,6 +79,5 @@ TEST(Interrupt, withinTimedOut) {
p.setInterruptHandler([&](const exception_wrapper& /* e */) { done.post(); });
p.getFuture().within(std::chrono::milliseconds(1));
// Give it 100ms to time out and call the interrupt handler
auto t = std::chrono::steady_clock::now() + std::chrono::milliseconds(100);
EXPECT_TRUE(done.timed_wait(t));
EXPECT_TRUE(done.try_wait_for(std::chrono::milliseconds(100)));
}
......@@ -37,7 +37,7 @@ TEST_F(EventBaseThreadTest, example) {
EXPECT_EQ(getCurrentThreadName().value(), "monkey");
done.post();
});
ASSERT_TRUE(done.timed_wait(seconds(1)));
ASSERT_TRUE(done.try_wait_for(seconds(1)));
}
TEST_F(EventBaseThreadTest, start_stop) {
......@@ -50,7 +50,7 @@ TEST_F(EventBaseThreadTest, start_stop) {
Baton<> done;
ebt.getEventBase()->runInEventBaseThread([&] { done.post(); });
ASSERT_TRUE(done.timed_wait(seconds(1)));
ASSERT_TRUE(done.try_wait_for(seconds(1)));
EXPECT_NE(nullptr, ebt.getEventBase());
ebt.stop();
......@@ -69,7 +69,7 @@ TEST_F(EventBaseThreadTest, move) {
Baton<> done;
ebt2.getEventBase()->runInEventBaseThread([&] { done.post(); });
ASSERT_TRUE(done.timed_wait(seconds(1)));
ASSERT_TRUE(done.try_wait_for(seconds(1)));
}
TEST_F(EventBaseThreadTest, self_move) {
......@@ -80,7 +80,7 @@ TEST_F(EventBaseThreadTest, self_move) {
Baton<> done;
ebt.getEventBase()->runInEventBaseThread([&] { done.post(); });
ASSERT_TRUE(done.timed_wait(seconds(1)));
ASSERT_TRUE(done.try_wait_for(seconds(1)));
}
TEST_F(EventBaseThreadTest, default_manager) {
......
......@@ -36,7 +36,7 @@ TEST_F(ScopedEventBaseThreadTest, example) {
Baton<> done;
sebt.getEventBase()->runInEventBaseThread([&] { done.post(); });
ASSERT_TRUE(done.timed_wait(seconds(1)));
ASSERT_TRUE(done.try_wait_for(seconds(1)));
}
TEST_F(ScopedEventBaseThreadTest, named_example) {
......@@ -51,7 +51,7 @@ TEST_F(ScopedEventBaseThreadTest, named_example) {
done.post();
});
ASSERT_TRUE(done.timed_wait(seconds(1)));
ASSERT_TRUE(done.try_wait_for(seconds(1)));
if (createdThreadName) {
ASSERT_EQ(kThreadName.toString(), createdThreadName.value());
}
......
......@@ -54,7 +54,7 @@ TEST(Baton, pingpong_nonblocking) {
run_pingpong_test<DeterministicAtomic, false>(1000);
}
/// Timed wait tests - Nonblocking Baton does not support timed_wait()
/// Timed wait tests - Nonblocking Baton does not support try_wait_until()
// Timed wait basic system clock tests
......
......@@ -58,7 +58,7 @@ void run_basic_timed_wait_tests() {
Baton<Atom> b;
b.post();
// tests if early delivery works fine
EXPECT_TRUE(b.timed_wait(Clock::now()));
EXPECT_TRUE(b.try_wait_until(Clock::now()));
}
template <template <typename> class Atom, typename Clock>
......@@ -66,7 +66,7 @@ void run_timed_wait_tmo_tests() {
Baton<Atom> b;
auto thr = DSched::thread([&] {
bool rv = b.timed_wait(Clock::now() + std::chrono::milliseconds(1));
bool rv = b.try_wait_until(Clock::now() + std::chrono::milliseconds(1));
// main thread is guaranteed to not post until timeout occurs
EXPECT_FALSE(rv);
});
......@@ -82,7 +82,7 @@ void run_timed_wait_regular_test() {
// std::condition_variable does math to convert the timeout to
// system_clock without handling overflow.
auto farFuture = Clock::now() + std::chrono::hours(1000);
bool rv = b.timed_wait(farFuture);
bool rv = b.try_wait_until(farFuture);
if (!std::is_same<Atom<int>, DeterministicAtomic<int>>::value) {
// DeterministicAtomic ignores actual times, so doesn't guarantee
// a lack of timeout
......
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