mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 01:03:57 +02:00
add mutex for _nodesRequestingJurisdictions to fix crash
This commit is contained in:
parent
e106514af0
commit
4874eda317
2 changed files with 19 additions and 2 deletions
|
@ -21,16 +21,22 @@ JurisdictionSender::JurisdictionSender(JurisdictionMap* map, PacketSenderNotify*
|
|||
ReceivedPacketProcessor(),
|
||||
_jurisdictionMap(map)
|
||||
{
|
||||
pthread_mutex_init(&_requestingNodeMutex, 0);
|
||||
}
|
||||
|
||||
JurisdictionSender::~JurisdictionSender() {
|
||||
pthread_mutex_destroy(&_requestingNodeMutex);
|
||||
}
|
||||
|
||||
|
||||
void JurisdictionSender::processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength) {
|
||||
if (packetData[0] == PACKET_TYPE_VOXEL_JURISDICTION_REQUEST) {
|
||||
Node* node = NodeList::getInstance()->nodeWithAddress(&senderAddress);
|
||||
if (node) {
|
||||
QUuid nodeUUID = node->getUUID();
|
||||
lock();
|
||||
lockRequestingNodes();
|
||||
_nodesRequestingJurisdictions.insert(nodeUUID);
|
||||
unlock();
|
||||
unlockRequestingNodes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +58,7 @@ bool JurisdictionSender::process() {
|
|||
}
|
||||
int nodeCount = 0;
|
||||
|
||||
lockRequestingNodes();
|
||||
for (std::set<QUuid>::iterator nodeIterator = _nodesRequestingJurisdictions.begin();
|
||||
nodeIterator != _nodesRequestingJurisdictions.end(); nodeIterator++) {
|
||||
|
||||
|
@ -66,6 +73,7 @@ bool JurisdictionSender::process() {
|
|||
_nodesRequestingJurisdictions.erase(nodeIterator);
|
||||
}
|
||||
}
|
||||
unlockRequestingNodes();
|
||||
|
||||
// set our packets per second to be the number of nodes
|
||||
setPacketsPerSecond(nodeCount);
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
static const int DEFAULT_PACKETS_PER_SECOND = 1;
|
||||
|
||||
JurisdictionSender(JurisdictionMap* map, PacketSenderNotify* notify = NULL);
|
||||
~JurisdictionSender();
|
||||
|
||||
void setJurisdiction(JurisdictionMap* map) { _jurisdictionMap = map; }
|
||||
|
||||
|
@ -33,7 +34,15 @@ public:
|
|||
protected:
|
||||
virtual void processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength);
|
||||
|
||||
/// Locks all the resources of the thread.
|
||||
void lockRequestingNodes() { pthread_mutex_lock(&_requestingNodeMutex); }
|
||||
|
||||
/// Unlocks all the resources of the thread.
|
||||
void unlockRequestingNodes() { pthread_mutex_unlock(&_requestingNodeMutex); }
|
||||
|
||||
|
||||
private:
|
||||
pthread_mutex_t _requestingNodeMutex;
|
||||
JurisdictionMap* _jurisdictionMap;
|
||||
std::set<QUuid> _nodesRequestingJurisdictions;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue