Skip to content
Snippets Groups Projects
Commit 261d0bc1 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Fix garbage bug using timer job

parent 5edd21d9
No related branches found
No related tags found
1 merge request!100Resolves #163 garbage segfault
This commit is part of merge request !100. Comments created here will be created in the context of that merge request.
......@@ -7,7 +7,7 @@
#define POOL_SIZE 10
#define DEBUG_MUTEX
//#define DEBUG_MUTEX
#define MUTEX_TIMEOUT 20
#if defined DEBUG_MUTEX
......
#include <ftl/net/universe.hpp>
#include <ftl/timer.hpp>
#include <chrono>
#ifdef WIN32
......@@ -54,6 +55,20 @@ Universe::Universe(nlohmann::json &config) :
_installBindings();
LOG(INFO) << "SEND BUFFER SIZE = " << send_size_;
ftl::timer::add(ftl::timer::kTimerIdle10, [this](int64_t ts) {
UNIQUE_LOCK(net_mutex_,lk);
if (ftl::pool.n_idle() == ftl::pool.size()) {
if (garbage_.size() > 0) LOG(INFO) << "Garbage collection";
while (garbage_.size() > 0) {
// FIXME: There is possibly still something with a peer pointer
// that is causing this throw an exception sometimes?
delete garbage_.front();
garbage_.pop_front();
}
}
return true;
});
}
Universe::~Universe() {
......@@ -184,17 +199,6 @@ void Universe::_installBindings() {
// Note: should be called inside a net lock
void Universe::_cleanupPeers() {
if (ftl::pool.n_idle() == ftl::pool.size()) {
if (garbage_.size() > 0) LOG(INFO) << "Garbage collection";
while (garbage_.size() > 0) {
// FIXME: There is possibly still something with a peer pointer
// that is causing this throw an exception sometimes?
delete garbage_.front();
garbage_.pop_front();
}
}
auto i = peers_.begin();
while (i != peers_.end()) {
if (!(*i)->isValid()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment