Skip to content

Commit

Permalink
Expose Sender::checkTimeouts() as public method.
Browse files Browse the repository at this point in the history
Will be used by a future non-polling interface.
  • Loading branch information
cstlee committed Oct 7, 2020
1 parent b617c47 commit 40345af
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/Mock/MockSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class MockSender : public Core::Sender {
(override));
MOCK_METHOD(void, handleErrorPacket, (Driver::Packet * packet), (override));
MOCK_METHOD(void, poll, (), (override));
MOCK_METHOD(void, checkTimeouts, (), (override));
};

} // namespace Mock
Expand Down
32 changes: 16 additions & 16 deletions src/Sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,22 @@ Sender::poll()
checkTimeouts();
}

/**
* Make incremental progress processing expired Sender timeouts.
*
* Pulled out of poll() for ease of testing.
*/
void
Sender::checkTimeouts()
{
uint index = nextBucketIndex.fetch_add(1, std::memory_order_relaxed) &
MessageBucketMap::HASH_KEY_MASK;
MessageBucket* bucket = messageBuckets.buckets.at(index);
uint64_t now = PerfUtils::Cycles::rdtsc();
checkPingTimeouts(now, bucket);
checkMessageTimeouts(now, bucket);
}

/**
* Destruct a Message. Will release all contained Packet objects.
*/
Expand Down Expand Up @@ -993,22 +1009,6 @@ Sender::checkPingTimeouts(uint64_t now, MessageBucket* bucket)
}
}

/**
* Process any Sender timeouts that have expired.
*
* Pulled out of poll() for ease of testing.
*/
void
Sender::checkTimeouts()
{
uint index = nextBucketIndex.fetch_add(1, std::memory_order_relaxed) &
MessageBucketMap::HASH_KEY_MASK;
MessageBucket* bucket = messageBuckets.buckets.at(index);
uint64_t now = PerfUtils::Cycles::rdtsc();
checkPingTimeouts(now, bucket);
checkMessageTimeouts(now, bucket);
}

/**
* Send out packets for any messages with unscheduled/granted bytes.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Sender {
virtual void handleUnknownPacket(Driver::Packet* packet);
virtual void handleErrorPacket(Driver::Packet* packet);
virtual void poll();
virtual void checkTimeouts();

private:
/// Forward declarations
Expand Down Expand Up @@ -403,7 +404,6 @@ class Sender {
void dropMessage(Sender::Message* message);
void checkMessageTimeouts(uint64_t now, MessageBucket* bucket);
void checkPingTimeouts(uint64_t now, MessageBucket* bucket);
void checkTimeouts();
void trySend();

/// Transport identifier.
Expand Down
22 changes: 11 additions & 11 deletions src/SenderTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,17 @@ TEST_F(SenderTest, poll)
sender->poll();
}

TEST_F(SenderTest, checkTimeouts)
{
Sender::MessageBucket* bucket = sender->messageBuckets.buckets.at(0);

EXPECT_EQ(0, sender->nextBucketIndex.load());

sender->checkTimeouts();

EXPECT_EQ(1, sender->nextBucketIndex.load());
}

TEST_F(SenderTest, Message_destructor)
{
const int MAX_RAW_PACKET_LENGTH = 2000;
Expand Down Expand Up @@ -1702,17 +1713,6 @@ TEST_F(SenderTest, checkPingTimeouts)
EXPECT_EQ(10001, message[5]->pingTimeout.expirationCycleTime);
}

TEST_F(SenderTest, checkTimeouts)
{
Sender::MessageBucket* bucket = sender->messageBuckets.buckets.at(0);

EXPECT_EQ(0, sender->nextBucketIndex.load());

sender->checkTimeouts();

EXPECT_EQ(1, sender->nextBucketIndex.load());
}

TEST_F(SenderTest, trySend_basic)
{
Protocol::MessageId id = {42, 10};
Expand Down

0 comments on commit 40345af

Please sign in to comment.