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
7474 _tree = new VoxelTree();
7575
7676 _tree->getRoot()->setVoxelSystem(this);
77− pthread_mutex_init(&_bufferWriteLock, NULL);
78− pthread_mutex_init(&_treeLock, NULL);
79− pthread_mutex_init(&_freeIndexLock, NULL);
8077
8178 VoxelTreeElement::addDeleteHook(this);
8279 VoxelTreeElement::addUpdateHook(this);
@@ -188,10 +185,10 @@ glBufferIndex VoxelSystem::getNextBufferIndex() { · 105 unmodified lines
188185 glBufferIndex output = GLBUFFER_INDEX_UNKNOWN;
189186 // if there's a free index, use it...
190187 if (_freeIndexes.size() > 0) {
191− pthread_mutex_lock(&_freeIndexLock);
188+ _freeIndexLock.lock();
192189 output = _freeIndexes.back();
193190 _freeIndexes.pop_back();
194− pthread_mutex_unlock(&_freeIndexLock);
191+ _freeIndexLock.unlock();
195192 } else {
196193 output = _voxelsInWriteArrays;
197194 _voxelsInWriteArrays++;
@@ -222,9 +219,9 @@ void VoxelSystem::freeBufferIndex(glBufferIndex index) { · 24 unmodified lines
222219 }
223220 if (!inList) {
224221 // make the index available for next node that needs to be drawn
225− pthread_mutex_lock(&_freeIndexLock);
222+ _freeIndexLock.lock();
226223 _freeIndexes.push_back(index);
227− pthread_mutex_unlock(&_freeIndexLock);
224+ _freeIndexLock.unlock();
228225
229226 // make the VBO slot "invisible" in case this slot is not used
230227 const glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX);
@@ -243,14 +240,14 @@ void VoxelSystem::clearFreeBufferIndexes() { · 12 unmodified lines
243240
244241 // clear out freeIndexes
245242 {
246− PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : pthread_mutex_lock(&_freeIndexLock)");
247− pthread_mutex_lock(&_freeIndexLock);
243+ PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : _freeIndexLock.lock()");
244+ _freeIndexLock.lock();
248245 }
249246 {
250247 PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : _freeIndexes.clear()");
251248 _freeIndexes.clear();
252249 }
253− pthread_mutex_unlock(&_freeIndexLock);
250+ _freeIndexLock.unlock();
254251 }
255252
256253 VoxelSystem::~VoxelSystem() {
@@ -259,9 +256,6 @@ VoxelSystem::~VoxelSystem() { · 2 unmodified lines
259256
260257 cleanupVoxelMemory();
261258 delete _tree;
262− pthread_mutex_destroy(&_bufferWriteLock);
263− pthread_mutex_destroy(&_treeLock);
264− pthread_mutex_destroy(&_freeIndexLock);
265259 }
266260
267261 void VoxelSystem::setMaxVoxels(int maxVoxels) {
@@ -345,7 +339,7 @@ void VoxelSystem::setVoxelsAsPoints(bool voxelsAsPoints) { · 77 unmodified lines
345339
346340 void VoxelSystem::cleanupVoxelMemory() {
347341 if (_initialized) {
348− pthread_mutex_lock(&_bufferWriteLock);
342+ _bufferWriteLock.lock();
349343 _initialized = false; // no longer initialized
350344 if (_useVoxelShader) {
351345 // these are used when in VoxelShader mode.
@@ -383,7 +377,7 @@ void VoxelSystem::cleanupVoxelMemory() { · 31 unmodified lines
383377 delete[] _writeVoxelDirtyArray;
384378 delete[] _readVoxelDirtyArray;
385379 _writeVoxelDirtyArray = _readVoxelDirtyArray = NULL;
386− pthread_mutex_unlock(&_bufferWriteLock);
380+ _bufferWriteLock.unlock();
387381 }
388382 }
389383
@@ -416,7 +410,7 @@ void VoxelSystem::setupFaceIndices(GLuint& faceVBOID, GLubyte faceIdentityIndice · 26 unmodified lines
416410 }
417411
418412 void VoxelSystem::initVoxelMemory() {
419− pthread_mutex_lock(&_bufferWriteLock);
413+ _bufferWriteLock.lock();
420414
421415 _memoryUsageRAM = 0;
422416 _memoryUsageVBO = 0; // our VBO allocations as we know them
@@ -531,7 +525,7 @@ void VoxelSystem::initVoxelMemory() { · 108 unmodified lines
531525
532526 _initialized = true;
533527
534− pthread_mutex_unlock(&_bufferWriteLock);
528+ _bufferWriteLock.unlock();
535529 }
536530
537531 void VoxelSystem::writeToSVOFile(const char* filename, VoxelTreeElement* element) const {
@@ -685,7 +679,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 147 unmodified lines
685679 }
686680
687681 // 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();
689683
690684 if (_voxelsUpdated) {
691685 _voxelsDirty=true;
@@ -694,7 +688,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 2 unmodified lines
694688 // copy the newly written data to the arrays designated for reading, only does something if _voxelsDirty && _voxelsUpdated
695689 copyWrittenDataToReadArrays(didWriteFullVBO);
696690
697− pthread_mutex_unlock(&_bufferWriteLock);
691+ _bufferWriteLock.unlock();
698692
699693 uint64_t end = usecTimestampNow();
700694 int elapsedmsec = (end - start) / 1000;
@@ -725,8 +719,8 @@ void VoxelSystem::setupNewVoxelsForDrawingSingleNode(bool allowBailEarly) { · 24 unmodified lines
725719 // lock on the buffer write lock so we can't modify the data when the GPU is reading it
726720 {
727721 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
728− "setupNewVoxelsForDrawingSingleNode()... pthread_mutex_lock(&_bufferWriteLock);");
729− pthread_mutex_lock(&_bufferWriteLock);
722+ "setupNewVoxelsForDrawingSingleNode()... _bufferWriteLock.lock();" );
723+ _bufferWriteLock.lock();
730724 }
731725
732726 _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
737731 // after...
738732 _voxelsUpdated = 0;
739733
740− pthread_mutex_unlock(&_bufferWriteLock);
734+ _bufferWriteLock.unlock();
741735
742736 uint64_t end = usecTimestampNow();
743737 int elapsedmsec = (end - start) / 1000;
@@ -2766,13 +2760,13 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() { · 2022 unmodified lines
27662760 }
27672761
27682762 void VoxelSystem::lockTree() {
2769− pthread_mutex_lock(&_treeLock);
2763+ _treeLock.lock();
27702764 _treeIsBusy = true;
27712765 }
27722766
27732767 void VoxelSystem::unlockTree() {
27742768 _treeIsBusy = false;
2775− pthread_mutex_unlock(&_treeLock);
2769+ _treeLock.unlock();
27762770 }
27772771
27782772