From 9ec0261d8c684cb9b7dc8a96b06a79dcb47562cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Fri, 17 Apr 2015 14:42:19 +0000 Subject: [PATCH] back to polygonf git-svn-id: svn://db.shs.com.ru/pip@106 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src/io/pipeer.cpp | 7 +++++++ src/io/pipeer.h | 2 +- src/thread/pitimer.cpp | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/io/pipeer.cpp b/src/io/pipeer.cpp index f182dd34..b2c6fb71 100755 --- a/src/io/pipeer.cpp +++ b/src/io/pipeer.cpp @@ -371,10 +371,12 @@ bool PIPeer::dataRead(uchar * readed, int size) { if (pi->isNeighbour()) { sba << int(6) << to << from << addr << time; //piCout << "ping from" << from << addr << ", send back to" << pi->name; + send_mutex.lock(); piForeachC (PeerInfo::Address & a, pi->addresses) { if (eth_send.send(a.address, sba)) diag_s.received(sba.size_s()); } + send_mutex.unlock(); } } } @@ -597,9 +599,11 @@ bool PIPeer::sendToNeighbour(PIPeer::PeerInfo * peer, const PIByteArray & ba) { PIString addr = peer->fastestAddress(); //piCout << "[PIPeer] sendToNeighbour" << peer->name << addr << ba.size_s() << "bytes ..."; //bool ok = peer->_neth->send(peer->_naddress, ba.data(), ba.size_s()); + send_mutex.lock(); bool ok = eth_send.send(addr, ba); //piCout << "[PIPeer] sendToNeighbour" << (ok ? "ok" : "fail"); if (ok) diag_d.sended(ba.size_s()); + send_mutex.unlock(); return ok; } @@ -679,6 +683,7 @@ void PIPeer::pingNeighbours() { piForeach (PeerInfo & p, peers) { //piCout << " ping neighbour" << p.name << p.ping(); if (!p.isNeighbour()) continue; + send_mutex.lock(); piForeach (PeerInfo::Address & a, p.addresses) { //piCout << " address" << a.address << a.wait_ping; if (a.wait_ping) { @@ -693,6 +698,7 @@ void PIPeer::pingNeighbours() { if (eth_send.send(a.address, sba)) diag_s.sended(sba.size_s()); } + send_mutex.unlock(); } } @@ -754,6 +760,7 @@ void PIPeer::reinit() { PIMutexLocker mbl(mc_mutex); PIMutexLocker ethl(eth_mutex); PIMutexLocker pl(peers_mutex); + PIMutexLocker sl(send_mutex); initNetwork(); eth_send.close(); eth_lo.stopThreadedRead(); diff --git a/src/io/pipeer.h b/src/io/pipeer.h index be5cd4b7..d3451540 100755 --- a/src/io/pipeer.h +++ b/src/io/pipeer.h @@ -185,7 +185,7 @@ private: PIEthernet::InterfaceList prev_ifaces; PIEthernet eth_send, eth_lo; PITimer timer; - PIMutex mc_mutex, eth_mutex, peers_mutex; + PIMutex mc_mutex, eth_mutex, peers_mutex, send_mutex; PeerInfo self_info; PIVector peers; diff --git a/src/thread/pitimer.cpp b/src/thread/pitimer.cpp index a845e3fa..2069c04c 100755 --- a/src/thread/pitimer.cpp +++ b/src/thread/pitimer.cpp @@ -120,6 +120,11 @@ _PITimerImp_Thread::~_PITimerImp_Thread() { void _PITimerImp_Thread::prepareStart(double interval_ms) { + if (interval_ms <= 0.) { + piCout << "Achtung! Start PITimer with interval <= 0!"; + piCout << "Achtung! Parent" << parent; + assert(interval_ms > 0.); + } st_inc = PISystemTime::fromMilliseconds(interval_ms); st_odt = st_inc * 5; if (st_odt.toSeconds() < 1.) st_odt = PISystemTime::fromSeconds(1.); @@ -302,6 +307,7 @@ _PITimerImp_Pool::Pool::~Pool() { stop(); if (!waitForFinish(100)) terminate(); + unlock(); timers.clear(); }