forgot to clear buffer

This commit is contained in:
Green Sky 2022-12-20 19:15:32 +01:00
parent ed72b27808
commit 05fd0940ea
No known key found for this signature in database

View File

@ -515,6 +515,8 @@ void toxThread(SharedContext* ctx) {
{ // pump from buffer to staging
const size_t max_commands = 1;
size_t number_of_commands_done = 0;
std::vector<Agent> empty_buffers;
{
std::lock_guard lg_staging{ctx->staging_mutex};
for (auto& [agent, buffer] : ctx->buffer) {
if (agent == agent_local) {
@ -535,10 +537,12 @@ void toxThread(SharedContext* ctx) {
continue;
}
// this can lead to dead locks, if other code does this wrong
std::vector<uint64_t> seq_to_remove;
{ // this can lead to dead locks, if other code does this wrong
std::lock_guard lg{ctx->command_lists_mutex};
for (; buffer.count(seq); seq++) {
ctx->command_lists[agent][seq] = buffer.at(seq);
seq_to_remove.push_back(seq);
number_of_commands_done++;
if (number_of_commands_done >= max_commands) {
@ -547,7 +551,19 @@ void toxThread(SharedContext* ctx) {
}
ctx->staging_frontier[agent] = seq;
}
ctx->should_gossip_remote.emplace(agent);
for (const auto key : seq_to_remove) {
buffer.erase(key);
}
if (buffer.empty()) {
empty_buffers.push_back(agent);
}
}
} // scope for staging lock
for (const auto& agent : empty_buffers) {
ctx->buffer.erase(agent);
}
}