mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-09 03:18:41 -05:00
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:
parent
4561752c45
commit
a134f81f95
@ -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 */
|
{
|
||||||
return;
|
/* nothing to do */
|
||||||
|
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,27 +311,40 @@ 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 ";
|
||||||
#endif
|
std::cerr << connect_count << " connection attempts and " << waitingIds.size();
|
||||||
|
std::cerr << " waiting connections. Can start ";
|
||||||
/* start some waiting id's */
|
std::cerr << (MAX_CONNECT_COUNT - connect_count) << " connection attempts.";
|
||||||
for (int i = connect_count; i < MAX_CONNECT_COUNT; i++) {
|
|
||||||
if (waitingIds.empty()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::string waitingId = waitingIds.front();
|
|
||||||
waitingIds.pop_front();
|
|
||||||
|
|
||||||
#ifdef PGRP_DEBUG
|
|
||||||
std::cerr << " pqipersongrp::statusChanged() id: " << waitingId << " connect peer";
|
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connectPeer(waitingId, true);
|
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||||
|
/* start some waiting id's */
|
||||||
|
for (int i = connect_count; i < MAX_CONNECT_COUNT; i++)
|
||||||
|
{
|
||||||
|
if (waitingIds.empty()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::string waitingId = waitingIds.front();
|
||||||
|
waitingIds.pop_front();
|
||||||
|
|
||||||
|
#ifdef PGRP_DEBUG
|
||||||
|
std::cerr << " pqipersongrp::statusChanged() id: " << waitingId << " connect peer";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
toConnect.push_back(waitingId);
|
||||||
|
}
|
||||||
|
} /* UNLOCKED */
|
||||||
|
|
||||||
|
std::list<std::string>::iterator cit;
|
||||||
|
for(cit = toConnect.begin(); cit != toConnect.end(); cit++)
|
||||||
|
{
|
||||||
|
connectPeer(*cit, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user