mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:29:32 +02:00
switch from pthread mutex to QMutex
This commit is contained in:
parent
2c30b8b5b4
commit
9bc4a3df41
12 changed files with 111 additions and 131 deletions
|
@ -74,9 +74,6 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels)
|
||||||
_tree = new VoxelTree();
|
_tree = new VoxelTree();
|
||||||
|
|
||||||
_tree->getRoot()->setVoxelSystem(this);
|
_tree->getRoot()->setVoxelSystem(this);
|
||||||
pthread_mutex_init(&_bufferWriteLock, NULL);
|
|
||||||
pthread_mutex_init(&_treeLock, NULL);
|
|
||||||
pthread_mutex_init(&_freeIndexLock, NULL);
|
|
||||||
|
|
||||||
VoxelTreeElement::addDeleteHook(this);
|
VoxelTreeElement::addDeleteHook(this);
|
||||||
VoxelTreeElement::addUpdateHook(this);
|
VoxelTreeElement::addUpdateHook(this);
|
||||||
|
@ -188,10 +185,10 @@ glBufferIndex VoxelSystem::getNextBufferIndex() {
|
||||||
glBufferIndex output = GLBUFFER_INDEX_UNKNOWN;
|
glBufferIndex output = GLBUFFER_INDEX_UNKNOWN;
|
||||||
// if there's a free index, use it...
|
// if there's a free index, use it...
|
||||||
if (_freeIndexes.size() > 0) {
|
if (_freeIndexes.size() > 0) {
|
||||||
pthread_mutex_lock(&_freeIndexLock);
|
_freeIndexLock.lock();
|
||||||
output = _freeIndexes.back();
|
output = _freeIndexes.back();
|
||||||
_freeIndexes.pop_back();
|
_freeIndexes.pop_back();
|
||||||
pthread_mutex_unlock(&_freeIndexLock);
|
_freeIndexLock.unlock();
|
||||||
} else {
|
} else {
|
||||||
output = _voxelsInWriteArrays;
|
output = _voxelsInWriteArrays;
|
||||||
_voxelsInWriteArrays++;
|
_voxelsInWriteArrays++;
|
||||||
|
@ -222,9 +219,9 @@ void VoxelSystem::freeBufferIndex(glBufferIndex index) {
|
||||||
}
|
}
|
||||||
if (!inList) {
|
if (!inList) {
|
||||||
// make the index available for next node that needs to be drawn
|
// make the index available for next node that needs to be drawn
|
||||||
pthread_mutex_lock(&_freeIndexLock);
|
_freeIndexLock.lock();
|
||||||
_freeIndexes.push_back(index);
|
_freeIndexes.push_back(index);
|
||||||
pthread_mutex_unlock(&_freeIndexLock);
|
_freeIndexLock.unlock();
|
||||||
|
|
||||||
// make the VBO slot "invisible" in case this slot is not used
|
// make the VBO slot "invisible" in case this slot is not used
|
||||||
const glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX);
|
const glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX);
|
||||||
|
@ -243,14 +240,14 @@ void VoxelSystem::clearFreeBufferIndexes() {
|
||||||
|
|
||||||
// clear out freeIndexes
|
// clear out freeIndexes
|
||||||
{
|
{
|
||||||
PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : pthread_mutex_lock(&_freeIndexLock)");
|
PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : _freeIndexLock.lock()");
|
||||||
pthread_mutex_lock(&_freeIndexLock);
|
_freeIndexLock.lock();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : _freeIndexes.clear()");
|
PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : _freeIndexes.clear()");
|
||||||
_freeIndexes.clear();
|
_freeIndexes.clear();
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&_freeIndexLock);
|
_freeIndexLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelSystem::~VoxelSystem() {
|
VoxelSystem::~VoxelSystem() {
|
||||||
|
@ -259,9 +256,6 @@ VoxelSystem::~VoxelSystem() {
|
||||||
|
|
||||||
cleanupVoxelMemory();
|
cleanupVoxelMemory();
|
||||||
delete _tree;
|
delete _tree;
|
||||||
pthread_mutex_destroy(&_bufferWriteLock);
|
|
||||||
pthread_mutex_destroy(&_treeLock);
|
|
||||||
pthread_mutex_destroy(&_freeIndexLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::setMaxVoxels(int maxVoxels) {
|
void VoxelSystem::setMaxVoxels(int maxVoxels) {
|
||||||
|
@ -345,7 +339,7 @@ void VoxelSystem::setVoxelsAsPoints(bool voxelsAsPoints) {
|
||||||
|
|
||||||
void VoxelSystem::cleanupVoxelMemory() {
|
void VoxelSystem::cleanupVoxelMemory() {
|
||||||
if (_initialized) {
|
if (_initialized) {
|
||||||
pthread_mutex_lock(&_bufferWriteLock);
|
_bufferWriteLock.lock();
|
||||||
_initialized = false; // no longer initialized
|
_initialized = false; // no longer initialized
|
||||||
if (_useVoxelShader) {
|
if (_useVoxelShader) {
|
||||||
// these are used when in VoxelShader mode.
|
// these are used when in VoxelShader mode.
|
||||||
|
@ -383,7 +377,7 @@ void VoxelSystem::cleanupVoxelMemory() {
|
||||||
delete[] _writeVoxelDirtyArray;
|
delete[] _writeVoxelDirtyArray;
|
||||||
delete[] _readVoxelDirtyArray;
|
delete[] _readVoxelDirtyArray;
|
||||||
_writeVoxelDirtyArray = _readVoxelDirtyArray = NULL;
|
_writeVoxelDirtyArray = _readVoxelDirtyArray = NULL;
|
||||||
pthread_mutex_unlock(&_bufferWriteLock);
|
_bufferWriteLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,7 +410,7 @@ void VoxelSystem::setupFaceIndices(GLuint& faceVBOID, GLubyte faceIdentityIndice
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::initVoxelMemory() {
|
void VoxelSystem::initVoxelMemory() {
|
||||||
pthread_mutex_lock(&_bufferWriteLock);
|
_bufferWriteLock.lock();
|
||||||
|
|
||||||
_memoryUsageRAM = 0;
|
_memoryUsageRAM = 0;
|
||||||
_memoryUsageVBO = 0; // our VBO allocations as we know them
|
_memoryUsageVBO = 0; // our VBO allocations as we know them
|
||||||
|
@ -531,7 +525,7 @@ void VoxelSystem::initVoxelMemory() {
|
||||||
|
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
|
|
||||||
pthread_mutex_unlock(&_bufferWriteLock);
|
_bufferWriteLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::writeToSVOFile(const char* filename, VoxelTreeElement* element) const {
|
void VoxelSystem::writeToSVOFile(const char* filename, VoxelTreeElement* element) const {
|
||||||
|
@ -685,7 +679,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// lock on the buffer write lock so we can't modify the data when the GPU is reading it
|
// lock on the buffer write lock so we can't modify the data when the GPU is reading it
|
||||||
pthread_mutex_lock(&_bufferWriteLock);
|
_bufferWriteLock.lock();
|
||||||
|
|
||||||
if (_voxelsUpdated) {
|
if (_voxelsUpdated) {
|
||||||
_voxelsDirty=true;
|
_voxelsDirty=true;
|
||||||
|
@ -694,7 +688,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() {
|
||||||
// copy the newly written data to the arrays designated for reading, only does something if _voxelsDirty && _voxelsUpdated
|
// copy the newly written data to the arrays designated for reading, only does something if _voxelsDirty && _voxelsUpdated
|
||||||
copyWrittenDataToReadArrays(didWriteFullVBO);
|
copyWrittenDataToReadArrays(didWriteFullVBO);
|
||||||
|
|
||||||
pthread_mutex_unlock(&_bufferWriteLock);
|
_bufferWriteLock.unlock();
|
||||||
|
|
||||||
uint64_t end = usecTimestampNow();
|
uint64_t end = usecTimestampNow();
|
||||||
int elapsedmsec = (end - start) / 1000;
|
int elapsedmsec = (end - start) / 1000;
|
||||||
|
@ -725,8 +719,8 @@ void VoxelSystem::setupNewVoxelsForDrawingSingleNode(bool allowBailEarly) {
|
||||||
// lock on the buffer write lock so we can't modify the data when the GPU is reading it
|
// lock on the buffer write lock so we can't modify the data when the GPU is reading it
|
||||||
{
|
{
|
||||||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
||||||
"setupNewVoxelsForDrawingSingleNode()... pthread_mutex_lock(&_bufferWriteLock);");
|
"setupNewVoxelsForDrawingSingleNode()... _bufferWriteLock.lock();" );
|
||||||
pthread_mutex_lock(&_bufferWriteLock);
|
_bufferWriteLock.lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
_voxelsDirty = true; // if we got this far, then we can assume some voxels are dirty
|
_voxelsDirty = true; // if we got this far, then we can assume some voxels are dirty
|
||||||
|
@ -737,7 +731,7 @@ void VoxelSystem::setupNewVoxelsForDrawingSingleNode(bool allowBailEarly) {
|
||||||
// after...
|
// after...
|
||||||
_voxelsUpdated = 0;
|
_voxelsUpdated = 0;
|
||||||
|
|
||||||
pthread_mutex_unlock(&_bufferWriteLock);
|
_bufferWriteLock.unlock();
|
||||||
|
|
||||||
uint64_t end = usecTimestampNow();
|
uint64_t end = usecTimestampNow();
|
||||||
int elapsedmsec = (end - start) / 1000;
|
int elapsedmsec = (end - start) / 1000;
|
||||||
|
@ -2766,13 +2760,13 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::lockTree() {
|
void VoxelSystem::lockTree() {
|
||||||
pthread_mutex_lock(&_treeLock);
|
_treeLock.lock();
|
||||||
_treeIsBusy = true;
|
_treeIsBusy = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::unlockTree() {
|
void VoxelSystem::unlockTree() {
|
||||||
_treeIsBusy = false;
|
_treeIsBusy = false;
|
||||||
pthread_mutex_unlock(&_treeLock);
|
_treeLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -260,8 +260,8 @@ private:
|
||||||
GLuint _vboIndicesFront;
|
GLuint _vboIndicesFront;
|
||||||
GLuint _vboIndicesBack;
|
GLuint _vboIndicesBack;
|
||||||
|
|
||||||
pthread_mutex_t _bufferWriteLock;
|
QMutex _bufferWriteLock;
|
||||||
pthread_mutex_t _treeLock;
|
QMutex _treeLock;
|
||||||
|
|
||||||
ViewFrustum _lastKnownViewFrustum;
|
ViewFrustum _lastKnownViewFrustum;
|
||||||
ViewFrustum _lastStableViewFrustum;
|
ViewFrustum _lastStableViewFrustum;
|
||||||
|
@ -287,7 +287,7 @@ private:
|
||||||
|
|
||||||
int _hookID;
|
int _hookID;
|
||||||
std::vector<glBufferIndex> _freeIndexes;
|
std::vector<glBufferIndex> _freeIndexes;
|
||||||
pthread_mutex_t _freeIndexLock;
|
QMutex _freeIndexLock;
|
||||||
|
|
||||||
void freeBufferIndex(glBufferIndex index);
|
void freeBufferIndex(glBufferIndex index);
|
||||||
void clearFreeBufferIndexes();
|
void clearFreeBufferIndexes();
|
||||||
|
|
|
@ -111,11 +111,11 @@ void LogDialog::resizeEvent(QResizeEvent*) {
|
||||||
|
|
||||||
void LogDialog::appendLogLine(QString logLine) {
|
void LogDialog::appendLogLine(QString logLine) {
|
||||||
if (isVisible()) {
|
if (isVisible()) {
|
||||||
pthread_mutex_lock(& _mutex);
|
_mutex.lock();
|
||||||
if (logLine.contains(_searchTerm, Qt::CaseInsensitive)) {
|
if (logLine.contains(_searchTerm, Qt::CaseInsensitive)) {
|
||||||
_logTextBox->appendPlainText(logLine.simplified());
|
_logTextBox->appendPlainText(logLine.simplified());
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(& _mutex);
|
_mutex.unlock();
|
||||||
_logTextBox->ensureCursorVisible();
|
_logTextBox->ensureCursorVisible();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,13 +140,12 @@ void LogDialog::handleSearchTextChanged(const QString searchText) {
|
||||||
|
|
||||||
void LogDialog::showLogData() {
|
void LogDialog::showLogData() {
|
||||||
_logTextBox->clear();
|
_logTextBox->clear();
|
||||||
pthread_mutex_lock(& _mutex);
|
_mutex.lock();
|
||||||
QStringList _logData = _logger->getLogData();
|
QStringList _logData = _logger->getLogData();
|
||||||
for (int i = 0; i < _logData.size(); ++i) {
|
for (int i = 0; i < _logData.size(); ++i) {
|
||||||
appendLogLine(_logData[i]);
|
appendLogLine(_logData[i]);
|
||||||
}
|
}
|
||||||
|
_mutex.unlock();
|
||||||
pthread_mutex_unlock(& _mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KeywordHighlighter::KeywordHighlighter(QTextDocument *parent) : QSyntaxHighlighter(parent), keywordFormat() {
|
KeywordHighlighter::KeywordHighlighter(QTextDocument *parent) : QSyntaxHighlighter(parent), keywordFormat() {
|
||||||
|
|
|
@ -10,12 +10,12 @@
|
||||||
#define __interface__LogDialog__
|
#define __interface__LogDialog__
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QMutex>
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QSyntaxHighlighter>
|
#include <QSyntaxHighlighter>
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include "AbstractLoggerInterface.h"
|
#include "AbstractLoggerInterface.h"
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ private:
|
||||||
QCheckBox* _extraDebuggingBox;
|
QCheckBox* _extraDebuggingBox;
|
||||||
QPushButton* _revealLogButton;
|
QPushButton* _revealLogButton;
|
||||||
QPlainTextEdit* _logTextBox;
|
QPlainTextEdit* _logTextBox;
|
||||||
pthread_mutex_t _mutex;
|
QMutex _mutex;
|
||||||
QString _searchTerm;
|
QString _searchTerm;
|
||||||
KeywordHighlighter* _highlighter;
|
KeywordHighlighter* _highlighter;
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,9 @@ JurisdictionSender::JurisdictionSender(JurisdictionMap* map, NODE_TYPE type, Pac
|
||||||
_jurisdictionMap(map)
|
_jurisdictionMap(map)
|
||||||
{
|
{
|
||||||
_nodeType = type;
|
_nodeType = type;
|
||||||
pthread_mutex_init(&_requestingNodeMutex, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JurisdictionSender::~JurisdictionSender() {
|
JurisdictionSender::~JurisdictionSender() {
|
||||||
pthread_mutex_destroy(&_requestingNodeMutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#define __shared__JurisdictionSender__
|
#define __shared__JurisdictionSender__
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <QMutex>
|
||||||
|
|
||||||
#include <PacketSender.h>
|
#include <PacketSender.h>
|
||||||
#include <ReceivedPacketProcessor.h>
|
#include <ReceivedPacketProcessor.h>
|
||||||
|
@ -38,14 +39,14 @@ protected:
|
||||||
virtual void processPacket(const HifiSockAddr& senderAddress, unsigned char* packetData, ssize_t packetLength);
|
virtual void processPacket(const HifiSockAddr& senderAddress, unsigned char* packetData, ssize_t packetLength);
|
||||||
|
|
||||||
/// Locks all the resources of the thread.
|
/// Locks all the resources of the thread.
|
||||||
void lockRequestingNodes() { pthread_mutex_lock(&_requestingNodeMutex); }
|
void lockRequestingNodes() { _requestingNodeMutex.lock(); }
|
||||||
|
|
||||||
/// Unlocks all the resources of the thread.
|
/// Unlocks all the resources of the thread.
|
||||||
void unlockRequestingNodes() { pthread_mutex_unlock(&_requestingNodeMutex); }
|
void unlockRequestingNodes() { _requestingNodeMutex.unlock(); }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pthread_mutex_t _requestingNodeMutex;
|
QMutex _requestingNodeMutex;
|
||||||
JurisdictionMap* _jurisdictionMap;
|
JurisdictionMap* _jurisdictionMap;
|
||||||
std::queue<QUuid> _nodesRequestingJurisdictions;
|
std::queue<QUuid> _nodesRequestingJurisdictions;
|
||||||
NODE_TYPE _nodeType;
|
NODE_TYPE _nodeType;
|
||||||
|
|
|
@ -43,20 +43,12 @@ Octree::Octree(bool shouldReaverage) :
|
||||||
_shouldReaverage(shouldReaverage),
|
_shouldReaverage(shouldReaverage),
|
||||||
_stopImport(false) {
|
_stopImport(false) {
|
||||||
_rootNode = NULL;
|
_rootNode = NULL;
|
||||||
|
|
||||||
pthread_mutex_init(&_encodeSetLock, NULL);
|
|
||||||
pthread_mutex_init(&_deleteSetLock, NULL);
|
|
||||||
pthread_mutex_init(&_deletePendingSetLock, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Octree::~Octree() {
|
Octree::~Octree() {
|
||||||
// delete the children of the root node
|
// delete the children of the root node
|
||||||
// this recursively deletes the tree
|
// this recursively deletes the tree
|
||||||
delete _rootNode;
|
delete _rootNode;
|
||||||
|
|
||||||
pthread_mutex_destroy(&_encodeSetLock);
|
|
||||||
pthread_mutex_destroy(&_deleteSetLock);
|
|
||||||
pthread_mutex_destroy(&_deletePendingSetLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recurses voxel tree calling the RecurseOctreeOperation function for each node.
|
// Recurses voxel tree calling the RecurseOctreeOperation function for each node.
|
||||||
|
@ -1504,53 +1496,53 @@ void dumpSetContents(const char* name, std::set<unsigned char*> set) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Octree::startEncoding(OctreeElement* node) {
|
void Octree::startEncoding(OctreeElement* node) {
|
||||||
pthread_mutex_lock(&_encodeSetLock);
|
_encodeSetLock.lock();
|
||||||
_codesBeingEncoded.insert(node->getOctalCode());
|
_codesBeingEncoded.insert(node->getOctalCode());
|
||||||
pthread_mutex_unlock(&_encodeSetLock);
|
_encodeSetLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Octree::doneEncoding(OctreeElement* node) {
|
void Octree::doneEncoding(OctreeElement* node) {
|
||||||
pthread_mutex_lock(&_encodeSetLock);
|
_encodeSetLock.lock();
|
||||||
_codesBeingEncoded.erase(node->getOctalCode());
|
_codesBeingEncoded.erase(node->getOctalCode());
|
||||||
pthread_mutex_unlock(&_encodeSetLock);
|
_encodeSetLock.unlock();
|
||||||
|
|
||||||
// if we have any pending delete codes, then delete them now.
|
// if we have any pending delete codes, then delete them now.
|
||||||
emptyDeleteQueue();
|
emptyDeleteQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Octree::startDeleting(const unsigned char* code) {
|
void Octree::startDeleting(const unsigned char* code) {
|
||||||
pthread_mutex_lock(&_deleteSetLock);
|
_deleteSetLock.lock();
|
||||||
_codesBeingDeleted.insert(code);
|
_codesBeingDeleted.insert(code);
|
||||||
pthread_mutex_unlock(&_deleteSetLock);
|
_deleteSetLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Octree::doneDeleting(const unsigned char* code) {
|
void Octree::doneDeleting(const unsigned char* code) {
|
||||||
pthread_mutex_lock(&_deleteSetLock);
|
_deleteSetLock.lock();
|
||||||
_codesBeingDeleted.erase(code);
|
_codesBeingDeleted.erase(code);
|
||||||
pthread_mutex_unlock(&_deleteSetLock);
|
_deleteSetLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Octree::isEncoding(const unsigned char* codeBuffer) {
|
bool Octree::isEncoding(const unsigned char* codeBuffer) {
|
||||||
pthread_mutex_lock(&_encodeSetLock);
|
_encodeSetLock.lock();
|
||||||
bool isEncoding = (_codesBeingEncoded.find(codeBuffer) != _codesBeingEncoded.end());
|
bool isEncoding = (_codesBeingEncoded.find(codeBuffer) != _codesBeingEncoded.end());
|
||||||
pthread_mutex_unlock(&_encodeSetLock);
|
_encodeSetLock.unlock();
|
||||||
return isEncoding;
|
return isEncoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Octree::queueForLaterDelete(const unsigned char* codeBuffer) {
|
void Octree::queueForLaterDelete(const unsigned char* codeBuffer) {
|
||||||
pthread_mutex_lock(&_deletePendingSetLock);
|
_deletePendingSetLock.lock();
|
||||||
_codesPendingDelete.insert(codeBuffer);
|
_codesPendingDelete.insert(codeBuffer);
|
||||||
pthread_mutex_unlock(&_deletePendingSetLock);
|
_deletePendingSetLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Octree::emptyDeleteQueue() {
|
void Octree::emptyDeleteQueue() {
|
||||||
pthread_mutex_lock(&_deletePendingSetLock);
|
_deletePendingSetLock.lock();
|
||||||
for (std::set<const unsigned char*>::iterator i = _codesPendingDelete.begin(); i != _codesPendingDelete.end(); ++i) {
|
for (std::set<const unsigned char*>::iterator i = _codesPendingDelete.begin(); i != _codesPendingDelete.end(); ++i) {
|
||||||
const unsigned char* codeToDelete = *i;
|
const unsigned char* codeToDelete = *i;
|
||||||
_codesBeingDeleted.erase(codeToDelete);
|
_codesBeingDeleted.erase(codeToDelete);
|
||||||
deleteOctalCodeFromTree(codeToDelete, COLLAPSE_EMPTY_TREE);
|
deleteOctalCodeFromTree(codeToDelete, COLLAPSE_EMPTY_TREE);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&_deletePendingSetLock);
|
_deletePendingSetLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Octree::cancelImport() {
|
void Octree::cancelImport() {
|
||||||
|
|
|
@ -290,7 +290,7 @@ protected:
|
||||||
/// descendants of them can not be deleted.
|
/// descendants of them can not be deleted.
|
||||||
std::set<const unsigned char*> _codesBeingEncoded;
|
std::set<const unsigned char*> _codesBeingEncoded;
|
||||||
/// mutex lock to protect the encoding set
|
/// mutex lock to protect the encoding set
|
||||||
pthread_mutex_t _encodeSetLock;
|
QMutex _encodeSetLock;
|
||||||
|
|
||||||
/// Called to indicate that a OctreeElement is in the process of being encoded.
|
/// Called to indicate that a OctreeElement is in the process of being encoded.
|
||||||
void startEncoding(OctreeElement* node);
|
void startEncoding(OctreeElement* node);
|
||||||
|
@ -303,7 +303,7 @@ protected:
|
||||||
/// descendants of them can not be encoded.
|
/// descendants of them can not be encoded.
|
||||||
std::set<const unsigned char*> _codesBeingDeleted;
|
std::set<const unsigned char*> _codesBeingDeleted;
|
||||||
/// mutex lock to protect the deleting set
|
/// mutex lock to protect the deleting set
|
||||||
pthread_mutex_t _deleteSetLock;
|
QMutex _deleteSetLock;
|
||||||
|
|
||||||
/// Called to indicate that an octal code is in the process of being deleted.
|
/// Called to indicate that an octal code is in the process of being deleted.
|
||||||
void startDeleting(const unsigned char* code);
|
void startDeleting(const unsigned char* code);
|
||||||
|
@ -313,7 +313,7 @@ protected:
|
||||||
/// instead queued for later delete
|
/// instead queued for later delete
|
||||||
std::set<const unsigned char*> _codesPendingDelete;
|
std::set<const unsigned char*> _codesPendingDelete;
|
||||||
/// mutex lock to protect the deleting set
|
/// mutex lock to protect the deleting set
|
||||||
pthread_mutex_t _deletePendingSetLock;
|
QMutex _deletePendingSetLock;
|
||||||
|
|
||||||
/// Adds an Octal Code to the set of codes that needs to be deleted
|
/// Adds an Octal Code to the set of codes that needs to be deleted
|
||||||
void queueForLaterDelete(const unsigned char* codeBuffer);
|
void queueForLaterDelete(const unsigned char* codeBuffer);
|
||||||
|
|
|
@ -14,12 +14,10 @@ GenericThread::GenericThread() :
|
||||||
_stopThread(false),
|
_stopThread(false),
|
||||||
_isThreaded(false) // assume non-threaded, must call initialize()
|
_isThreaded(false) // assume non-threaded, must call initialize()
|
||||||
{
|
{
|
||||||
pthread_mutex_init(&_mutex, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericThread::~GenericThread() {
|
GenericThread::~GenericThread() {
|
||||||
terminate();
|
terminate();
|
||||||
pthread_mutex_destroy(&_mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericThread::initialize(bool isThreaded) {
|
void GenericThread::initialize(bool isThreaded) {
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#define __shared__GenericThread__
|
#define __shared__GenericThread__
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
#include <QMutex>
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
@ -41,15 +42,15 @@ public:
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/// Locks all the resources of the thread.
|
/// Locks all the resources of the thread.
|
||||||
void lock() { pthread_mutex_lock(&_mutex); }
|
void lock() { _mutex.lock(); }
|
||||||
|
|
||||||
/// Unlocks all the resources of the thread.
|
/// Unlocks all the resources of the thread.
|
||||||
void unlock() { pthread_mutex_unlock(&_mutex); }
|
void unlock() { _mutex.unlock(); }
|
||||||
|
|
||||||
bool isStillRunning() const { return !_stopThread; }
|
bool isStillRunning() const { return !_stopThread; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pthread_mutex_t _mutex;
|
QMutex _mutex;
|
||||||
|
|
||||||
bool _stopThread;
|
bool _stopThread;
|
||||||
bool _isThreaded;
|
bool _isThreaded;
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -35,7 +34,6 @@ Node::Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const
|
||||||
_isAlive(true),
|
_isAlive(true),
|
||||||
_clockSkewUsec(0)
|
_clockSkewUsec(0)
|
||||||
{
|
{
|
||||||
pthread_mutex_init(&_mutex, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Node::~Node() {
|
Node::~Node() {
|
||||||
|
@ -44,8 +42,6 @@ Node::~Node() {
|
||||||
}
|
}
|
||||||
|
|
||||||
delete _bytesReceivedMovingAverage;
|
delete _bytesReceivedMovingAverage;
|
||||||
|
|
||||||
pthread_mutex_destroy(&_mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Names of Node Types
|
// Names of Node Types
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QUuid>
|
#include <QtCore/QUuid>
|
||||||
|
#include <QMutex>
|
||||||
|
|
||||||
#include "HifiSockAddr.h"
|
#include "HifiSockAddr.h"
|
||||||
#include "NodeData.h"
|
#include "NodeData.h"
|
||||||
|
@ -72,11 +73,11 @@ public:
|
||||||
int getClockSkewUsec() const { return _clockSkewUsec; }
|
int getClockSkewUsec() const { return _clockSkewUsec; }
|
||||||
void setClockSkewUsec(int clockSkew) { _clockSkewUsec = clockSkew; }
|
void setClockSkewUsec(int clockSkew) { _clockSkewUsec = clockSkew; }
|
||||||
|
|
||||||
void lock() { pthread_mutex_lock(&_mutex); }
|
void lock() { _mutex.lock(); }
|
||||||
|
|
||||||
/// returns false if lock failed, true if you got the lock
|
/// returns false if lock failed, true if you got the lock
|
||||||
bool trylock() { return (pthread_mutex_trylock(&_mutex) == 0); }
|
bool trylock() { return _mutex.tryLock(); }
|
||||||
void unlock() { pthread_mutex_unlock(&_mutex); }
|
void unlock() { _mutex.unlock(); }
|
||||||
|
|
||||||
static void printLog(Node const&);
|
static void printLog(Node const&);
|
||||||
|
|
||||||
|
@ -97,7 +98,7 @@ private:
|
||||||
bool _isAlive;
|
bool _isAlive;
|
||||||
int _pingMs;
|
int _pingMs;
|
||||||
int _clockSkewUsec;
|
int _clockSkewUsec;
|
||||||
pthread_mutex_t _mutex;
|
QMutex _mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
int unpackNodeId(unsigned char *packedData, uint16_t *nodeId);
|
int unpackNodeId(unsigned char *packedData, uint16_t *nodeId);
|
||||||
|
|
Loading…
Reference in a new issue