History

tighten up mutex locks to keep at 60 fps

ZappoMan committed 13 years ago

Commit 54364a21 parent f6981fe2 files · +9 −11Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+9−7
@@ -538,15 +538,15 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 537 unmodified lines
538538 int numBytesPacketHeader = numBytesForPacketHeader(sourceBuffer);
539539 unsigned char* voxelData = sourceBuffer + numBytesPacketHeader;
540540
541− pthread_mutex_lock(&_treeLock);
542−
543541 switch(command) {
544542 case PACKET_TYPE_VOXEL_DATA: {
545543 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
546544 "readBitstreamToTree()");
547545 // ask the VoxelTree to read the bitstream into the tree
548546 ReadBitstreamToTreeParams args(WANT_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceID());
547+ pthread_mutex_lock(&_treeLock);
549548 _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
549+ pthread_mutex_unlock(&_treeLock);
550550 }
551551 break;
552552 case PACKET_TYPE_VOXEL_DATA_MONOCHROME: {
@@ -554,7 +554,9 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 1 unmodified line
554554 "readBitstreamToTree()");
555555 // ask the VoxelTree to read the MONOCHROME bitstream into the tree
556556 ReadBitstreamToTreeParams args(NO_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceID());
557+ pthread_mutex_lock(&_treeLock);
557558 _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
559+ pthread_mutex_unlock(&_treeLock);
558560 }
559561 break;
560562 case PACKET_TYPE_Z_COMMAND:
@@ -572,7 +574,9 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 11 unmodified lines
572574 while (totalLength <= numBytes) {
573575 if (0==strcmp(command,(char*)"erase all")) {
574576 qDebug("got Z message == erase all\n");
577+ pthread_mutex_lock(&_treeLock);
575578 _tree->eraseAllVoxels();
579+ pthread_mutex_unlock(&_treeLock);
576580 _voxelsInReadArrays = _voxelsInWriteArrays = 0; // better way to do this??
577581 }
578582 if (0==strcmp(command,(char*)"add scene")) {
@@ -590,8 +594,6 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 11 unmodified lines
590594 setupNewVoxelsForDrawingSingleNode(DONT_BAIL_EARLY);
591595 }
592596
593− pthread_mutex_unlock(&_treeLock);
594−
595597 Application::getInstance()->getBandwidthMeter()->inputStream(BandwidthMeter::VOXELS).updateValue(numBytes);
596598
597599 return numBytes;
@@ -1824,13 +1826,13 @@ VoxelNode* VoxelSystem::getVoxelAt(float x, float y, float z, float s) const { · 1226 unmodified lines
18241826
18251827 void VoxelSystem::createVoxel(float x, float y, float z, float s,
18261828 unsigned char red, unsigned char green, unsigned char blue, bool destructive) {
1827− pthread_mutex_lock(&_treeLock);
18281829
18291830 //qDebug("VoxelSystem::createVoxel(%f,%f,%f,%f)\n",x,y,z,s);
1831+ pthread_mutex_lock(&_treeLock);
18301832 _tree->createVoxel(x, y, z, s, red, green, blue, destructive);
1831− setupNewVoxelsForDrawing();
1832−
18331833 pthread_mutex_unlock(&_treeLock);
1834+
1835+ setupNewVoxelsForDrawing();
18341836 };
18351837
18361838 void VoxelSystem::createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, rgbColor color, bool destructive) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t