History

switch from pthread mutex to QMutex

Brad Hefta-Gaub committed 12 years ago

Commit 9bc4a3d1 parent 2c30b8b12 files · +111 −131Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 12 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+18−24
@@ -74,9 +74,6 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 73 unmodified lines
74 _tree = new VoxelTree();74 _tree = new VoxelTree();
75 75
76 _tree->getRoot()->setVoxelSystem(this);76 _tree->getRoot()->setVoxelSystem(this);
77 pthread_mutex_init(&_bufferWriteLock, NULL);
78 pthread_mutex_init(&_treeLock, NULL);
79 pthread_mutex_init(&_freeIndexLock, NULL);
80 77
81 VoxelTreeElement::addDeleteHook(this);78 VoxelTreeElement::addDeleteHook(this);
82 VoxelTreeElement::addUpdateHook(this);79 VoxelTreeElement::addUpdateHook(this);
@@ -188,10 +185,10 @@ glBufferIndex VoxelSystem::getNextBufferIndex() { · 105 unmodified lines
188 glBufferIndex output = GLBUFFER_INDEX_UNKNOWN;185 glBufferIndex output = GLBUFFER_INDEX_UNKNOWN;
189 // if there's a free index, use it...186 // if there's a free index, use it...
190 if (_freeIndexes.size() > 0) {187 if (_freeIndexes.size() > 0) {
191 pthread_mutex_lock(&_freeIndexLock);188 _freeIndexLock.lock();
192 output = _freeIndexes.back();189 output = _freeIndexes.back();
193 _freeIndexes.pop_back();190 _freeIndexes.pop_back();
194 pthread_mutex_unlock(&_freeIndexLock);191 _freeIndexLock.unlock();
195 } else {192 } else {
196 output = _voxelsInWriteArrays;193 output = _voxelsInWriteArrays;
197 _voxelsInWriteArrays++;194 _voxelsInWriteArrays++;
@@ -222,9 +219,9 @@ void VoxelSystem::freeBufferIndex(glBufferIndex index) { · 24 unmodified lines
222 }219 }
223 if (!inList) {220 if (!inList) {
224 // make the index available for next node that needs to be drawn221 // make the index available for next node that needs to be drawn
225 pthread_mutex_lock(&_freeIndexLock);222 _freeIndexLock.lock();
226 _freeIndexes.push_back(index);223 _freeIndexes.push_back(index);
227 pthread_mutex_unlock(&_freeIndexLock);224 _freeIndexLock.unlock();
228 225
229 // make the VBO slot "invisible" in case this slot is not used226 // make the VBO slot "invisible" in case this slot is not used
230 const glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX);227 const glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX);
@@ -243,14 +240,14 @@ void VoxelSystem::clearFreeBufferIndexes() { · 12 unmodified lines
243 240
244 // clear out freeIndexes241 // clear out freeIndexes
245 {242 {
246 PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : pthread_mutex_lock(&_freeIndexLock)");243 PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : _freeIndexLock.lock()");
247 pthread_mutex_lock(&_freeIndexLock);244 _freeIndexLock.lock();
248 }245 }
249 {246 {
250 PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : _freeIndexes.clear()");247 PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : _freeIndexes.clear()");
251 _freeIndexes.clear();248 _freeIndexes.clear();
252 }249 }
253 pthread_mutex_unlock(&_freeIndexLock);250 _freeIndexLock.unlock();
254}251}
255 252
256VoxelSystem::~VoxelSystem() {253VoxelSystem::~VoxelSystem() {
@@ -259,9 +256,6 @@ VoxelSystem::~VoxelSystem() { · 2 unmodified lines
259 256
260 cleanupVoxelMemory();257 cleanupVoxelMemory();
261 delete _tree;258 delete _tree;
262 pthread_mutex_destroy(&_bufferWriteLock);
263 pthread_mutex_destroy(&_treeLock);
264 pthread_mutex_destroy(&_freeIndexLock);
265}259}
266 260
267void VoxelSystem::setMaxVoxels(int maxVoxels) {261void VoxelSystem::setMaxVoxels(int maxVoxels) {
@@ -345,7 +339,7 @@ void VoxelSystem::setVoxelsAsPoints(bool voxelsAsPoints) { · 77 unmodified lines
345 339
346void VoxelSystem::cleanupVoxelMemory() {340void VoxelSystem::cleanupVoxelMemory() {
347 if (_initialized) {341 if (_initialized) {
348 pthread_mutex_lock(&_bufferWriteLock);342 _bufferWriteLock.lock();
349 _initialized = false; // no longer initialized343 _initialized = false; // no longer initialized
350 if (_useVoxelShader) {344 if (_useVoxelShader) {
351 // these are used when in VoxelShader mode.345 // these are used when in VoxelShader mode.
@@ -383,7 +377,7 @@ void VoxelSystem::cleanupVoxelMemory() { · 31 unmodified lines
383 delete[] _writeVoxelDirtyArray;377 delete[] _writeVoxelDirtyArray;
384 delete[] _readVoxelDirtyArray;378 delete[] _readVoxelDirtyArray;
385 _writeVoxelDirtyArray = _readVoxelDirtyArray = NULL;379 _writeVoxelDirtyArray = _readVoxelDirtyArray = NULL;
386 pthread_mutex_unlock(&_bufferWriteLock);380 _bufferWriteLock.unlock();
387 }381 }
388}382}
389 383
@@ -416,7 +410,7 @@ void VoxelSystem::setupFaceIndices(GLuint& faceVBOID, GLubyte faceIdentityIndice · 26 unmodified lines
416}410}
417 411
418void VoxelSystem::initVoxelMemory() {412void VoxelSystem::initVoxelMemory() {
419 pthread_mutex_lock(&_bufferWriteLock);413 _bufferWriteLock.lock();
420 414
421 _memoryUsageRAM = 0;415 _memoryUsageRAM = 0;
422 _memoryUsageVBO = 0; // our VBO allocations as we know them416 _memoryUsageVBO = 0; // our VBO allocations as we know them
@@ -531,7 +525,7 @@ void VoxelSystem::initVoxelMemory() { · 108 unmodified lines
531 525
532 _initialized = true;526 _initialized = true;
533 527
534 pthread_mutex_unlock(&_bufferWriteLock);528 _bufferWriteLock.unlock();
535}529}
536 530
537void VoxelSystem::writeToSVOFile(const char* filename, VoxelTreeElement* element) const {531void VoxelSystem::writeToSVOFile(const char* filename, VoxelTreeElement* element) const {
@@ -685,7 +679,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 147 unmodified lines
685 }679 }
686 680
687 // lock on the buffer write lock so we can't modify the data when the GPU is reading it681 // lock on the buffer write lock so we can't modify the data when the GPU is reading it
688 pthread_mutex_lock(&_bufferWriteLock);682 _bufferWriteLock.lock();
689 683
690 if (_voxelsUpdated) {684 if (_voxelsUpdated) {
691 _voxelsDirty=true;685 _voxelsDirty=true;
@@ -694,7 +688,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 2 unmodified lines
694 // copy the newly written data to the arrays designated for reading, only does something if _voxelsDirty && _voxelsUpdated688 // copy the newly written data to the arrays designated for reading, only does something if _voxelsDirty && _voxelsUpdated
695 copyWrittenDataToReadArrays(didWriteFullVBO);689 copyWrittenDataToReadArrays(didWriteFullVBO);
696 690
697 pthread_mutex_unlock(&_bufferWriteLock);691 _bufferWriteLock.unlock();
698 692
699 uint64_t end = usecTimestampNow();693 uint64_t end = usecTimestampNow();
700 int elapsedmsec = (end - start) / 1000;694 int elapsedmsec = (end - start) / 1000;
@@ -725,8 +719,8 @@ void VoxelSystem::setupNewVoxelsForDrawingSingleNode(bool allowBailEarly) { · 24 unmodified lines
725 // lock on the buffer write lock so we can't modify the data when the GPU is reading it719 // lock on the buffer write lock so we can't modify the data when the GPU is reading it
726 {720 {
727 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),721 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
728 "setupNewVoxelsForDrawingSingleNode()... pthread_mutex_lock(&_bufferWriteLock);");722 "setupNewVoxelsForDrawingSingleNode()... _bufferWriteLock.lock();" );
729 pthread_mutex_lock(&_bufferWriteLock);723 _bufferWriteLock.lock();
730 }724 }
731 725
732 _voxelsDirty = true; // if we got this far, then we can assume some voxels are dirty726 _voxelsDirty = true; // if we got this far, then we can assume some voxels are dirty
@@ -737,7 +731,7 @@ void VoxelSystem::setupNewVoxelsForDrawingSingleNode(bool allowBailEarly) { · 4 unmodified lines
737 // after...731 // after...
738 _voxelsUpdated = 0;732 _voxelsUpdated = 0;
739 733
740 pthread_mutex_unlock(&_bufferWriteLock);734 _bufferWriteLock.unlock();
741 735
742 uint64_t end = usecTimestampNow();736 uint64_t end = usecTimestampNow();
743 int elapsedmsec = (end - start) / 1000;737 int elapsedmsec = (end - start) / 1000;
@@ -2766,13 +2760,13 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() { · 2022 unmodified lines
2766}2760}
2767 2761
2768void VoxelSystem::lockTree() {2762void VoxelSystem::lockTree() {
2769 pthread_mutex_lock(&_treeLock);2763 _treeLock.lock();
2770 _treeIsBusy = true;2764 _treeIsBusy = true;
2771}2765}
2772 2766
2773void VoxelSystem::unlockTree() {2767void VoxelSystem::unlockTree() {
2774 _treeIsBusy = false;2768 _treeIsBusy = false;
2775 pthread_mutex_unlock(&_treeLock);2769 _treeLock.unlock();
2776}2770}
2777 2771
2778 2772