Protected waitingIds with Mutex.

NB: This is windows code - which I cannot compile. Sorry for any bugs.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5891 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-11-25 20:52:10 +00:00
parent 4561752c45
commit a134f81f95

View File

@ -262,19 +262,23 @@ void pqipersongrp::statusChanged()
if (RsInit::isWindowsXP() == false) { if (RsInit::isWindowsXP() == false) {
/* the problem only exist in Windows XP */ /* the problem only exist in Windows XP */
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
waitingIds.clear(); waitingIds.clear();
return; return;
} }
/* there is no need for a mutex for waitingIds */ {
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
if (waitingIds.empty()) { if (waitingIds.empty())
{
/* nothing to do */ /* nothing to do */
return; return;
} }
}
/* check for active connections and start waiting id's */ /* check for active connections and start waiting id's */
long connect_count = 0; long connect_count = 0;
std::list<std::string> toConnect;
{ {
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
@ -307,14 +311,19 @@ void pqipersongrp::statusChanged()
} }
} }
} /* UNLOCKED */
#ifdef PGRP_DEBUG #ifdef PGRP_DEBUG
std::cerr << "pqipersongrp::statusChanged() There are " << connect_count << " connection attempts and " << waitingIds.size() << " waiting connections. Can start " << (MAX_CONNECT_COUNT - connect_count) << " connection attempts." << std::endl; std::cerr << "pqipersongrp::statusChanged() There are ";
std::cerr << connect_count << " connection attempts and " << waitingIds.size();
std::cerr << " waiting connections. Can start ";
std::cerr << (MAX_CONNECT_COUNT - connect_count) << " connection attempts.";
std::cerr << std::endl;
#endif #endif
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
/* start some waiting id's */ /* start some waiting id's */
for (int i = connect_count; i < MAX_CONNECT_COUNT; i++) { for (int i = connect_count; i < MAX_CONNECT_COUNT; i++)
{
if (waitingIds.empty()) { if (waitingIds.empty()) {
break; break;
} }
@ -326,8 +335,16 @@ void pqipersongrp::statusChanged()
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
connectPeer(waitingId, true); toConnect.push_back(waitingId);
} }
} /* UNLOCKED */
std::list<std::string>::iterator cit;
for(cit = toConnect.begin(); cit != toConnect.end(); cit++)
{
connectPeer(*cit, true);
}
} }
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
#endif #endif