Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prioritize broadcast commands #30

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/CrazyradioThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,30 @@ void CrazyradioThread::run()
break;
}

bool all_queues_empty = true;
bool any_outstanding_broadcasts = false;
for (auto con : connections_copy) {
if (!con->queue_send_.empty() || con->retry_) {
all_queues_empty = false;
if (con->broadcast_) {
any_outstanding_broadcasts = true;
break;
}
}
}

for (auto con : connections_copy) {

// if this queue has nothing to do and we can't even send a ping, skip
if (con->queue_send_.empty() && !con->retry_ && (!con->useAutoPing_ || !all_queues_empty)) {
continue;
}

// if there are outstanding broadcasts, skip all non-broadcasting connections
if (any_outstanding_broadcasts && !con->broadcast_) {
continue;
}

// for (auto con : connections_) {
// const std::lock_guard<std::mutex> con_lock(con->alive_mutex_);
// if (!con->alive_) {
Expand Down Expand Up @@ -206,7 +229,7 @@ void CrazyradioThread::run()
p = con->queue_send_.top();
con->queue_send_.pop();
--con->statistics_.enqueued_count;
} else if (!con->useAutoPing_)
} else if (!con->useAutoPing_ || !all_queues_empty)
{
continue;
}
Expand Down Expand Up @@ -260,7 +283,7 @@ void CrazyradioThread::run()
}
}
}
else if (con->useAutoPing_)
else if (con->useAutoPing_ && all_queues_empty)
{
ack = radio.sendPacket(ping, sizeof(ping));
++con->statistics_.sent_count;
Expand Down