Browse Source

reduce start and stop time

pull/1274/head
orignal 6 years ago
parent
commit
0e9074aaba
  1. 14
      libi2pd/Transports.cpp

14
libi2pd/Transports.cpp

@ -35,8 +35,11 @@ namespace transport
void DHKeysPairSupplier::Stop () void DHKeysPairSupplier::Stop ()
{ {
m_IsRunning = false; {
m_Acquired.notify_one (); std::unique_lock<std::mutex> l(m_AcquiredMutex);
m_IsRunning = false;
m_Acquired.notify_one ();
}
if (m_Thread) if (m_Thread)
{ {
m_Thread->join (); m_Thread->join ();
@ -50,19 +53,20 @@ namespace transport
while (m_IsRunning) while (m_IsRunning)
{ {
int num, total = 0; int num, total = 0;
while ((num = m_QueueSize - (int)m_Queue.size ()) > 0 && total < 20) while ((num = m_QueueSize - (int)m_Queue.size ()) > 0 && total < 10)
{ {
CreateDHKeysPairs (num); CreateDHKeysPairs (num);
total += num; total += num;
} }
if (total >= 20) if (total >= 10)
{ {
LogPrint (eLogWarning, "Transports: ", total, " DH keys generated at the time"); LogPrint (eLogWarning, "Transports: ", total, " DH keys generated at the time");
std::this_thread::sleep_for (std::chrono::seconds(1)); // take a break std::this_thread::sleep_for (std::chrono::seconds(1)); // take a break
} }
else else
{ {
std::unique_lock<std::mutex> l(m_AcquiredMutex); std::unique_lock<std::mutex> l(m_AcquiredMutex);
if (!m_IsRunning) break;
m_Acquired.wait (l); // wait for element gets acquired m_Acquired.wait (l); // wait for element gets acquired
} }
} }

Loading…
Cancel
Save