Skip to content

Commit 886c562

Browse files
committed
vtd: Avoid spin-logging on empty RDB message queue
Instead loop in the transceiver's receive function until messages arrive.
1 parent 7422e3e commit 886c562

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

plugins/vtd/src/rdb_codec.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,6 @@ void RdbCodec::process(RDB_MSG_t* msg, bool& restart, cloe::Duration& sim_time)
288288
}
289289

290290
void RdbCodec::step(uint64_t frame_number, bool& restart, cloe::Duration& sim_time) {
291-
// TODO(ben): For some reason, this loop here goes round and round with zero
292-
// messages received. Either we should stop dumping the log message when
293-
// there are no messages to process, or we should have the receive function
294-
// only return when there are messages?
295291
while (processing_frame_ || frame_number_ < frame_number || restart) {
296292
auto messages = rdb_->receive();
297293
rdb_logger()->trace("RdbCodec: processing {} messages [frame={}]", messages.size(),

plugins/vtd/src/rdb_transceiver_tcp.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "rdb_transceiver.hpp" // for RdbTransceiver
3636
#include "vtd_logger.hpp" // for rdb_logger
3737

38+
#define VTD_RDB_WAIT_SLEEP_MS 1
39+
3840
namespace vtd {
3941

4042
/**
@@ -50,6 +52,9 @@ class RdbTransceiverTcp : public RdbTransceiver, public cloe::utility::TcpTransc
5052

5153
std::vector<std::shared_ptr<RDB_MSG_t>> receive() override {
5254
std::vector<std::shared_ptr<RDB_MSG_t>> msgs;
55+
while (!this->has()) {
56+
std::this_thread::sleep_for(cloe::Milliseconds{VTD_RDB_WAIT_SLEEP_MS});
57+
}
5358
while (this->has()) {
5459
num_received_++;
5560
msgs.push_back(this->receive_wait());

0 commit comments

Comments
 (0)