Skip to content

Commit

Permalink
ut: replace mt_waker_ by g_sem
Browse files Browse the repository at this point in the history
  • Loading branch information
fchn289 committed Oct 27, 2023
1 parent 6a48b3c commit 2910379
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ut/thread/MtInQueueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "UniLog.hpp"

#define MT_IN_Q_TEST
#include "MT_PingMainTH.hpp"
#include "MtInQueue.hpp"
#undef MT_IN_Q_TEST

Expand All @@ -39,12 +40,11 @@ struct MtInQueueTest : public Test, public UniLog

// -------------------------------------------------------------------------------------------
MtInQueue mtQ_;
MT_Semaphore mt_waker_;
};

#define FIFO
// ***********************************************************************************************
TEST_F(MtInQueueTest, GOLD_simple_fifo_without_waker)
TEST_F(MtInQueueTest, GOLD_simple_fifo)
{
MtInQueue mtQ;
mtQ.mt_push<int>(make_shared<int>(1));
Expand All @@ -69,7 +69,7 @@ TEST_F(MtInQueueTest, GOLD_sparsePush_fifo)
{
auto msg = mtQ_.pop<int>();
if (msg) ASSERT_EQ(nHdl++, *msg) << "REQ: fifo";
else mt_waker_.mt_timedwait(); // REQ: less CPU than repeat pop() or this_thread::yield()
else g_sem.mt_timedwait(); // REQ: less CPU than repeat pop() or this_thread::yield()
}
INF("REQ(sleep 1us/push): e2e user=0.354s->0.123s, sys=0.412s->0.159s")
}
Expand Down Expand Up @@ -114,19 +114,19 @@ TEST_F(MtInQueueTest, size_and_nowait)
{
mtQ_.mt_push<int>(make_shared<int>(1));
ASSERT_EQ(1u, mtQ_.mt_size()) << "REQ: inc size" << endl;
mt_waker_.mt_timedwait();
g_sem.mt_timedwait();
ASSERT_EQ(1u, mtQ_.mt_size()) << "REQ: wait() ret immediately since mtQ_ not empty" << endl;

mtQ_.mt_push<int>(make_shared<int>(2));
ASSERT_EQ(2u, mtQ_.mt_size()) << "REQ: inc size" << endl;

EXPECT_EQ(1, *(mtQ_.pop<int>())) << "REQ: fifo";
ASSERT_EQ(1u, mtQ_.mt_size()) << "REQ: dec size" << endl;
mt_waker_.mt_timedwait();
g_sem.mt_timedwait();
ASSERT_EQ(1u, mtQ_.mt_size()) << "REQ: wait() ret immediately since mtQ_ not empty" << endl;

mtQ_.mt_push<int>(make_shared<int>(3));
mt_waker_.mt_timedwait();
g_sem.mt_timedwait();
ASSERT_EQ(2u, mtQ_.mt_size()) << "REQ: wait() ret immediately since mtQ_ not empty" << endl;

EXPECT_EQ(2, *(mtQ_.pop<int>())) << "REQ: keep fifo after wait_for()";
Expand Down

0 comments on commit 2910379

Please sign in to comment.