Skip to content

Commit

Permalink
Remove condition_variable and mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
szmyd committed Sep 12, 2023
1 parent 6e917d8 commit 625e7c3
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions src/test/test_fiber_shared_mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ class SharedMutexTest : public testing::Test {
iomgr::FiberManagerLib::shared_mutex m_cb_mtx;
std::vector< iomgr::io_fiber_t > m_fibers;
uint64_t m_count_per_fiber{0};
std::mutex m_test_done_mtx;
std::condition_variable m_test_done_cv;
uint32_t m_test_count{0};
std::atomic_uint32_t m_test_count{0};

protected:
void SetUp() override {
Expand Down Expand Up @@ -88,10 +86,7 @@ class SharedMutexTest : public testing::Test {
}

LOGINFO("Fiber completed {} of exclusive locks", m_count_per_fiber);
{
std::unique_lock lg(m_test_done_mtx);
if (--m_test_count == 0) { m_test_done_cv.notify_one(); }
}
--m_test_count;
}

void all_reader() {
Expand All @@ -100,10 +95,7 @@ class SharedMutexTest : public testing::Test {
}

LOGINFO("Fiber completed {} of shared locks", m_count_per_fiber);
{
std::unique_lock lg(m_test_done_mtx);
if (--m_test_count == 0) { m_test_done_cv.notify_one(); }
}
--m_test_count;
}

void random_reader_writer() {
Expand All @@ -124,10 +116,7 @@ class SharedMutexTest : public testing::Test {
}

LOGINFO("Fiber completed shared_locks={} exclusive_locks={}", read_count, write_count);
{
std::unique_lock lg(m_test_done_mtx);
if (--m_test_count == 0) { m_test_done_cv.notify_one(); }
}
--m_test_count;
}

void write_once() {
Expand All @@ -154,22 +143,18 @@ TEST_F(SharedMutexTest, single_writer_multiple_readers) {
folly::makeSemiFuture().via(iomanager.fiberExecutor(*it)).thenValue([this](auto) { all_reader(); }));
}
folly::collectAll(calls).via(&e).get();

{
std::unique_lock< std::mutex > lk(m_test_done_mtx);
EXPECT_EQ(0, m_test_count);
}
EXPECT_EQ(0, m_test_count.load());
}

TEST_F(SharedMutexTest, random_reader_writers) {
auto e = folly::QueuedImmediateExecutor();
auto calls = std::vector< folly::SemiFuture< folly::Unit > >();
for (const auto& f : m_fibers) {
iomanager.run_on_forget(f, [this]() { random_reader_writer(); });
}

{
std::unique_lock< std::mutex > lk(m_test_done_mtx);
m_test_done_cv.wait(lk, [&]() { return m_test_count == 0; });
calls.push_back(
folly::makeSemiFuture().via(iomanager.fiberExecutor(f)).thenValue([this](auto) { all_reader(); }));
}
folly::collectAll(calls).via(&e).get();
EXPECT_EQ(0, m_test_count.load());
}

int main(int argc, char* argv[]) {
Expand Down

0 comments on commit 625e7c3

Please sign in to comment.