mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-08 22:13:48 +01:00
add NetDb::WaitForReady
This commit is contained in:
parent
fec49e5609
commit
10ffdb2766
2 changed files with 17 additions and 5 deletions
10
NetDb.cpp
10
NetDb.cpp
|
@ -23,7 +23,7 @@ namespace data
|
|||
{
|
||||
NetDb netdb;
|
||||
|
||||
NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr), m_Reseeder (nullptr), m_Storage("netDb", "r", "routerInfo-", "dat"), m_HiddenMode(false)
|
||||
NetDb::NetDb (): m_Ready(new std::promise<void>()), m_IsRunning (false), m_Thread (nullptr), m_Reseeder (nullptr), m_Storage("netDb", "r", "routerInfo-", "dat"), m_HiddenMode(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ namespace data
|
|||
|
||||
m_IsRunning = true;
|
||||
m_Thread = new std::thread (std::bind (&NetDb::Run, this));
|
||||
m_Ready->set_value();
|
||||
}
|
||||
|
||||
void NetDb::Stop ()
|
||||
|
@ -69,6 +70,13 @@ namespace data
|
|||
}
|
||||
}
|
||||
|
||||
void NetDb::WaitForReady()
|
||||
{
|
||||
m_Ready->get_future().wait();
|
||||
delete m_Ready;
|
||||
m_Ready = nullptr;
|
||||
}
|
||||
|
||||
void NetDb::Run ()
|
||||
{
|
||||
uint32_t lastSave = 0, lastPublish = 0, lastExploratory = 0, lastManageRequest = 0, lastDestinationCleanup = 0;
|
||||
|
|
4
NetDb.h
4
NetDb.h
|
@ -8,6 +8,7 @@
|
|||
#include <string>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <future>
|
||||
|
||||
#include "Base.h"
|
||||
#include "Gzip.h"
|
||||
|
@ -48,6 +49,8 @@ namespace data
|
|||
|
||||
void Start ();
|
||||
void Stop ();
|
||||
/** block until netdb is ready, call only once*/
|
||||
void WaitForReady();
|
||||
|
||||
bool AddRouterInfo (const uint8_t * buf, int len);
|
||||
bool AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len);
|
||||
|
@ -109,6 +112,7 @@ namespace data
|
|||
std::shared_ptr<const RouterInfo> GetRandomRouter (Filter filter) const;
|
||||
|
||||
private:
|
||||
std::promise<void> * m_Ready;
|
||||
|
||||
mutable std::mutex m_LeaseSetsMutex;
|
||||
std::map<IdentHash, std::shared_ptr<LeaseSet> > m_LeaseSets;
|
||||
|
|
Loading…
Add table
Reference in a new issue