mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-07 07:44:13 +00:00
use m_IsSaving flag for saving RouterInfo
This commit is contained in:
parent
e4ba07a540
commit
adc230acde
@ -34,7 +34,7 @@ namespace i2p
|
|||||||
m_Error (eRouterErrorNone), m_ErrorV6 (eRouterErrorNone),
|
m_Error (eRouterErrorNone), m_ErrorV6 (eRouterErrorNone),
|
||||||
m_Testing (false), m_TestingV6 (false), m_NetID (I2PD_NET_ID),
|
m_Testing (false), m_TestingV6 (false), m_NetID (I2PD_NET_ID),
|
||||||
m_PublishReplyToken (0), m_IsHiddenMode (false),
|
m_PublishReplyToken (0), m_IsHiddenMode (false),
|
||||||
m_Rng(i2p::util::GetMonotonicMicroseconds () % 1000000LL)
|
m_Rng(i2p::util::GetMonotonicMicroseconds () % 1000000LL), m_IsSaving (false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,12 +78,6 @@ namespace i2p
|
|||||||
m_Service->Stop ();
|
m_Service->Stop ();
|
||||||
CleanUp (); // GarlicDestination
|
CleanUp (); // GarlicDestination
|
||||||
}
|
}
|
||||||
if (m_SavingRouterInfo.valid ())
|
|
||||||
{
|
|
||||||
m_SaveBuffer = nullptr;
|
|
||||||
m_SavingRouterInfo.get ();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<i2p::data::RouterInfo::Buffer> RouterContext::CopyRouterInfoBuffer () const
|
std::shared_ptr<i2p::data::RouterInfo::Buffer> RouterContext::CopyRouterInfoBuffer () const
|
||||||
@ -271,14 +265,10 @@ namespace i2p
|
|||||||
std::lock_guard<std::mutex> l(m_SaveBufferMutex);
|
std::lock_guard<std::mutex> l(m_SaveBufferMutex);
|
||||||
m_SaveBuffer = buffer;
|
m_SaveBuffer = buffer;
|
||||||
}
|
}
|
||||||
bool isSaving = m_SavingRouterInfo.valid ();
|
bool isSaving = false;
|
||||||
if (isSaving && m_SavingRouterInfo.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
|
if (m_IsSaving.compare_exchange_strong (isSaving, true)) // try to save only if not being saved
|
||||||
{
|
{
|
||||||
m_SavingRouterInfo.get ();
|
auto savingRouterInfo = std::async (std::launch::async, [this]()
|
||||||
isSaving = false;
|
|
||||||
}
|
|
||||||
if (!isSaving) // try to save only if not being saved
|
|
||||||
m_SavingRouterInfo = std::async (std::launch::async, [this]()
|
|
||||||
{
|
{
|
||||||
std::shared_ptr<i2p::data::RouterInfo::Buffer> buffer;
|
std::shared_ptr<i2p::data::RouterInfo::Buffer> buffer;
|
||||||
while (m_SaveBuffer)
|
while (m_SaveBuffer)
|
||||||
@ -291,7 +281,9 @@ namespace i2p
|
|||||||
if (buffer)
|
if (buffer)
|
||||||
i2p::data::RouterInfo::SaveToFile (i2p::fs::DataDirPath (ROUTER_INFO), buffer);
|
i2p::data::RouterInfo::SaveToFile (i2p::fs::DataDirPath (ROUTER_INFO), buffer);
|
||||||
}
|
}
|
||||||
|
m_IsSaving = false;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
m_LastUpdateTime = i2p::util::GetSecondsSinceEpoch ();
|
m_LastUpdateTime = i2p::util::GetSecondsSinceEpoch ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <future>
|
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
@ -267,9 +266,9 @@ namespace garlic
|
|||||||
bool m_IsHiddenMode; // not publish
|
bool m_IsHiddenMode; // not publish
|
||||||
mutable std::mutex m_RouterInfoMutex;
|
mutable std::mutex m_RouterInfoMutex;
|
||||||
std::mt19937 m_Rng;
|
std::mt19937 m_Rng;
|
||||||
std::future<void> m_SavingRouterInfo;
|
|
||||||
std::shared_ptr<i2p::data::RouterInfo::Buffer> m_SaveBuffer;
|
std::shared_ptr<i2p::data::RouterInfo::Buffer> m_SaveBuffer;
|
||||||
std::mutex m_SaveBufferMutex; // TODO: make m_SaveBuffer atomic
|
std::mutex m_SaveBufferMutex; // TODO: make m_SaveBuffer atomic
|
||||||
|
std::atomic<bool> m_IsSaving;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern RouterContext context;
|
extern RouterContext context;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user