mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 02:03:57 +02:00
replace the Node mutex with a QMutex
This commit is contained in:
parent
53d435006c
commit
57f977668f
5 changed files with 13 additions and 33 deletions
|
@ -2030,7 +2030,7 @@ void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm::
|
|||
PerformanceWarning warn(showWarnings, "Application::updateAvatars()");
|
||||
|
||||
foreach(SharedNodePointer node, NodeList::getInstance()->getNodeHash()) {
|
||||
node->lock();
|
||||
QMutexLocker(&node->getMutex());
|
||||
if (node->getLinkedData()) {
|
||||
Avatar *avatar = (Avatar *)node->getLinkedData();
|
||||
if (!avatar->isInitialized()) {
|
||||
|
@ -2039,7 +2039,6 @@ void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm::
|
|||
avatar->simulate(deltaTime, NULL);
|
||||
avatar->setMouseRay(mouseRayOrigin, mouseRayDirection);
|
||||
}
|
||||
node->unlock();
|
||||
}
|
||||
|
||||
// simulate avatar fades
|
||||
|
@ -3759,7 +3758,7 @@ void Application::renderAvatars(bool forceRenderHead, bool selfAvatarOnly) {
|
|||
NodeList* nodeList = NodeList::getInstance();
|
||||
|
||||
foreach(SharedNodePointer node, nodeList->getNodeHash()) {
|
||||
node->lock();
|
||||
QMutexLocker(&node->getMutex());
|
||||
|
||||
if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
|
||||
Avatar *avatar = (Avatar *)node->getLinkedData();
|
||||
|
@ -3769,8 +3768,6 @@ void Application::renderAvatars(bool forceRenderHead, bool selfAvatarOnly) {
|
|||
avatar->render(false);
|
||||
avatar->setDisplayingLookatVectors(Menu::getInstance()->isOptionChecked(MenuOption::LookAtVectors));
|
||||
}
|
||||
|
||||
node->unlock();
|
||||
}
|
||||
|
||||
// render avatar fades
|
||||
|
|
|
@ -34,7 +34,7 @@ bool OctreeSendThread::process() {
|
|||
|
||||
if (node) {
|
||||
// make sure the node list doesn't kill our node while we're using it
|
||||
if (node->trylock()) {
|
||||
if (node->getMutex().tryLock()) {
|
||||
gotLock = true;
|
||||
OctreeQueryNode* nodeData = NULL;
|
||||
|
||||
|
@ -51,7 +51,7 @@ bool OctreeSendThread::process() {
|
|||
packetsSent = packetDistributor(node.data(), nodeData, viewFrustumChanged);
|
||||
}
|
||||
|
||||
node->unlock(); // we're done with this node for now.
|
||||
node->getMutex().unlock(); // we're done with this node for now.
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -33,9 +33,10 @@ Node::Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const
|
|||
_bytesReceivedMovingAverage(NULL),
|
||||
_linkedData(NULL),
|
||||
_isAlive(true),
|
||||
_clockSkewUsec(0)
|
||||
_clockSkewUsec(0),
|
||||
_mutex()
|
||||
{
|
||||
pthread_mutex_init(&_mutex, 0);
|
||||
|
||||
}
|
||||
|
||||
Node::~Node() {
|
||||
|
@ -46,8 +47,6 @@ Node::~Node() {
|
|||
}
|
||||
|
||||
delete _bytesReceivedMovingAverage;
|
||||
|
||||
pthread_mutex_destroy(&_mutex);
|
||||
}
|
||||
|
||||
// Names of Node Types
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#endif
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QMutex>
|
||||
#include <QtCore/QUuid>
|
||||
|
||||
#include "HifiSockAddr.h"
|
||||
|
@ -73,13 +74,7 @@ public:
|
|||
int getClockSkewUsec() const { return _clockSkewUsec; }
|
||||
void setClockSkewUsec(int clockSkew) { _clockSkewUsec = clockSkew; }
|
||||
|
||||
void lock() { pthread_mutex_lock(&_mutex); }
|
||||
|
||||
/// returns false if lock failed, true if you got the lock
|
||||
bool trylock() { return (pthread_mutex_trylock(&_mutex) == 0); }
|
||||
void unlock() { pthread_mutex_unlock(&_mutex); }
|
||||
|
||||
static void printLog(Node const&);
|
||||
QMutex& getMutex() { return _mutex; }
|
||||
|
||||
private:
|
||||
// privatize copy and assignment operator to disallow Node copying
|
||||
|
@ -98,12 +93,9 @@ private:
|
|||
bool _isAlive;
|
||||
int _pingMs;
|
||||
int _clockSkewUsec;
|
||||
pthread_mutex_t _mutex;
|
||||
QMutex _mutex;
|
||||
};
|
||||
|
||||
int unpackNodeId(unsigned char *packedData, uint16_t *nodeId);
|
||||
int packNodeId(unsigned char *packStore, uint16_t nodeId);
|
||||
|
||||
QDebug operator<<(QDebug debug, const Node &message);
|
||||
|
||||
#endif /* defined(__hifi__Node__) */
|
||||
|
|
|
@ -227,7 +227,7 @@ void NodeList::processBulkNodeData(const HifiSockAddr& senderAddress, unsigned c
|
|||
}
|
||||
|
||||
int NodeList::updateNodeWithData(Node *node, const HifiSockAddr& senderSockAddr, unsigned char *packetData, int dataBytes) {
|
||||
node->lock();
|
||||
QMutexLocker(&node->getMutex());
|
||||
|
||||
node->setLastHeardMicrostamp(usecTimestampNow());
|
||||
|
||||
|
@ -244,12 +244,9 @@ int NodeList::updateNodeWithData(Node *node, const HifiSockAddr& senderSockAddr,
|
|||
|
||||
int numParsedBytes = node->getLinkedData()->parseData(packetData, dataBytes);
|
||||
|
||||
node->unlock();
|
||||
|
||||
return numParsedBytes;
|
||||
} else {
|
||||
// we weren't able to match the sender address to the address we have for this node, unlock and don't parse
|
||||
node->unlock();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -695,7 +692,7 @@ SharedNodePointer NodeList::addOrUpdateNode(const QUuid& uuid, char nodeType,
|
|||
return newNodeSharedPointer;
|
||||
} else {
|
||||
SharedNodePointer node = matchingNodeItem.value();
|
||||
matchingNodeItem.value()->lock();
|
||||
QMutexLocker(&node->getMutex());
|
||||
|
||||
if (node->getType() == NODE_TYPE_AUDIO_MIXER ||
|
||||
node->getType() == NODE_TYPE_VOXEL_SERVER ||
|
||||
|
@ -716,8 +713,6 @@ SharedNodePointer NodeList::addOrUpdateNode(const QUuid& uuid, char nodeType,
|
|||
qDebug() << "Local socket change for node" << *node << "\n";
|
||||
}
|
||||
|
||||
node->unlock();
|
||||
|
||||
// we had this node already, do nothing for now
|
||||
return node;
|
||||
}
|
||||
|
@ -797,7 +792,7 @@ void NodeList::removeSilentNodes() {
|
|||
|
||||
SharedNodePointer node = nodeItem.value();
|
||||
|
||||
node->lock();
|
||||
QMutexLocker(&node->getMutex());
|
||||
|
||||
if ((usecTimestampNow() - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) {
|
||||
|
||||
|
@ -805,9 +800,6 @@ void NodeList::removeSilentNodes() {
|
|||
_nodeHash.erase(nodeItem);
|
||||
}
|
||||
|
||||
// unlock the node
|
||||
node->unlock();
|
||||
|
||||
nodeItem++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue