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

Merge branch 'master' of gitlab.utu.fi:nicolas.pope/ftl

parents 5edd21d9 6ce66362
No related branches found
No related tags found
No related merge requests found
Pipeline #13099 passed
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#define POOL_SIZE 10 #define POOL_SIZE 10
#define DEBUG_MUTEX //#define DEBUG_MUTEX
#define MUTEX_TIMEOUT 20 #define MUTEX_TIMEOUT 20
#if defined DEBUG_MUTEX #if defined DEBUG_MUTEX
......
#include <ftl/net/universe.hpp> #include <ftl/net/universe.hpp>
#include <ftl/timer.hpp>
#include <chrono> #include <chrono>
#ifdef WIN32 #ifdef WIN32
...@@ -38,6 +39,8 @@ Universe::Universe() : ...@@ -38,6 +39,8 @@ Universe::Universe() :
reconnect_attempts_(50), reconnect_attempts_(50),
thread_(Universe::__start, this) { thread_(Universe::__start, this) {
_installBindings(); _installBindings();
LOG(WARNING) << "Deprecated Universe constructor";
} }
Universe::Universe(nlohmann::json &config) : Universe::Universe(nlohmann::json &config) :
...@@ -53,7 +56,22 @@ Universe::Universe(nlohmann::json &config) : ...@@ -53,7 +56,22 @@ Universe::Universe(nlohmann::json &config) :
_installBindings(); _installBindings();
LOG(INFO) << "SEND BUFFER SIZE = " << send_size_; // Add an idle timer job to garbage collect peer objects
// Note: Important to be a timer job to ensure no other timer jobs are
// using the object.
ftl::timer::add(ftl::timer::kTimerIdle10, [this](int64_t ts) {
if (garbage_.size() > 0) {
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) {
delete garbage_.front();
garbage_.pop_front();
}
}
}
return true;
});
} }
Universe::~Universe() { Universe::~Universe() {
...@@ -184,17 +202,6 @@ void Universe::_installBindings() { ...@@ -184,17 +202,6 @@ void Universe::_installBindings() {
// Note: should be called inside a net lock // Note: should be called inside a net lock
void Universe::_cleanupPeers() { 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(); auto i = peers_.begin();
while (i != peers_.end()) { while (i != peers_.end()) {
if (!(*i)->isValid()) { if (!(*i)->isValid()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment