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