summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErwin Coumans <erwincoumans@google.com>2021-05-07 15:37:56 +0000
committerErwin Coumans <erwincoumans@google.com>2021-05-07 15:37:56 +0000
commitcd76d605a9b5cb63279134c2fc8757475aa3edc6 (patch)
tree8891a56f5410caa019a855d80b0e1585b2eb62ee
parentf14911c998fc0ff57d4ec626b7c1ebd80033a5c5 (diff)
downloadbullet3-cd76d605a9b5cb63279134c2fc8757475aa3edc6.tar.gz
more fixes for tsan
-rw-r--r--examples/SharedMemory/PhysicsServerExample.cpp149
1 files changed, 80 insertions, 69 deletions
diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp
index 64cbacc90..d10c0e317 100644
--- a/examples/SharedMemory/PhysicsServerExample.cpp
+++ b/examples/SharedMemory/PhysicsServerExample.cpp
@@ -133,7 +133,6 @@ enum MultiThreadedGUIHelperCommunicationEnums
eGUIUserDebugRemoveAllParameters,
eGUIHelperResetCamera,
eGUIHelperChangeGraphicsInstanceFlags,
- eGUIHelperSetRgbBackground,
};
#include <stdio.h>
@@ -710,7 +709,7 @@ public:
{
BT_PROFILE("mainThreadRelease");
- getCriticalSection()->setSharedParam(1, eGUIHelperIdle);
+ setSharedParam(1, eGUIHelperIdle);
getCriticalSection3()->lock();
getCriticalSection2()->unlock();
getCriticalSection()->lock();
@@ -830,10 +829,11 @@ public:
btVector3 m_color3;
virtual void createRigidBodyGraphicsObject(btRigidBody* body, const btVector3& color)
{
- m_body = body;
- m_color3 = color;
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperCreateRigidBodyGraphicsObject);
+
+ m_body = body;
+ m_color3 = color;
+ setSharedParam(1, eGUIHelperCreateRigidBodyGraphicsObject);
workerThreadWait();
}
@@ -842,19 +842,21 @@ public:
virtual void createCollisionObjectGraphicsObject(btCollisionObject* obj, const btVector3& color)
{
- m_obj = obj;
- m_color2 = color;
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperCreateCollisionObjectGraphicsObject);
+
+ m_obj = obj;
+ m_color2 = color;
+ setSharedParam(1, eGUIHelperCreateCollisionObjectGraphicsObject);
workerThreadWait();
}
btCollisionShape* m_colShape;
virtual void createCollisionShapeGraphicsObject(btCollisionShape* collisionShape)
{
- m_colShape = collisionShape;
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperCreateCollisionShapeGraphicsObject);
+
+ m_colShape = collisionShape;
+ setSharedParam(1, eGUIHelperCreateCollisionShapeGraphicsObject);
workerThreadWait();
}
@@ -901,9 +903,10 @@ public:
virtual void removeTexture(int textureUid)
{
- m_removeTextureUid = textureUid;
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperRemoveTexture);
+
+ m_removeTextureUid = textureUid;
+ setSharedParam(1, eGUIHelperRemoveTexture);
workerThreadWait();
}
@@ -913,11 +916,12 @@ public:
int m_updateNumShapeVertices;
virtual void updateShape(int shapeIndex, float* vertices, int numVertices)
{
- m_updateShapeIndex = shapeIndex;
+ m_cs->lock();
+
+ m_updateShapeIndex = shapeIndex;
m_updateShapeVertices = vertices;
m_updateNumShapeVertices = numVertices;
- m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperUpdateShape);
+ setSharedParam(1, eGUIHelperUpdateShape);
workerThreadWait();
}
virtual int registerTexture(const unsigned char* texels, int width, int height)
@@ -927,12 +931,13 @@ public:
{
return *cachedTexture;
}
- m_texels = texels;
+ m_cs->lock();
+
+ m_texels = texels;
m_textureWidth = width;
m_textureHeight = height;
- m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperRegisterTexture);
+ setSharedParam(1, eGUIHelperRegisterTexture);
workerThreadWait();
m_cachedTextureIds.insert(texels, m_textureId);
@@ -940,31 +945,44 @@ public:
}
virtual int registerGraphicsShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType, int textureId)
{
- m_vertices = vertices;
+ m_cs->lock();
+ m_csGUI->lock();
+ m_vertices = vertices;
m_numvertices = numvertices;
m_indices = indices;
m_numIndices = numIndices;
m_primitiveType = primitiveType;
m_textureId = textureId;
-
- m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperRegisterGraphicsShape);
+ m_csGUI->unlock();
+ setSharedParam(1, eGUIHelperRegisterGraphicsShape);
workerThreadWait();
- return m_shapeIndex;
+ m_csGUI->lock();
+ int shapeIndex = m_shapeIndex;
+ m_csGUI->unlock();
+
+
+ return shapeIndex;
}
int m_visualizerFlag;
int m_visualizerEnable;
int m_renderedFrames;
+ void setSharedParam(int slot, int param)
+ {
+ m_csGUI->lock();
+ m_cs->setSharedParam(slot, param);
+ m_csGUI->unlock();
+ }
void setVisualizerFlag(int flag, int enable)
{
- m_visualizerFlag = flag;
+ m_cs->lock();
+
+ m_visualizerFlag = flag;
m_visualizerEnable = enable;
- m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperSetVisualizerFlag);
+ setSharedParam(1, eGUIHelperSetVisualizerFlag);
workerThreadWait();
}
@@ -982,16 +1000,16 @@ public:
m_scaling = scaling;
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperRegisterGraphicsInstance);
+ setSharedParam(1, eGUIHelperRegisterGraphicsInstance);
workerThreadWait();
return m_instanceId;
}
virtual void removeAllGraphicsInstances()
{
+ m_cs->lock();
m_cachedTextureIds.clear();
- m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperRemoveAllGraphicsInstances);
+ setSharedParam(1, eGUIHelperRemoveAllGraphicsInstances);
workerThreadWait();
}
@@ -1000,7 +1018,7 @@ public:
{
m_graphicsInstanceRemove = graphicsUid;
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperRemoveGraphicsInstance);
+ setSharedParam(1, eGUIHelperRemoveGraphicsInstance);
workerThreadWait();
}
@@ -1011,7 +1029,7 @@ public:
{
m_getShapeIndex_instance = instance;
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperGetShapeIndexFromInstance);
+ setSharedParam(1, eGUIHelperGetShapeIndexFromInstance);
getShapeIndex_shapeIndex = -1;
workerThreadWait();
return getShapeIndex_shapeIndex;
@@ -1024,7 +1042,7 @@ public:
m_graphicsInstanceChangeTextureShapeIndex = shapeIndex;
m_graphicsInstanceChangeTextureId = textureUid;
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperChangeGraphicsInstanceTextureId);
+ setSharedParam(1, eGUIHelperChangeGraphicsInstanceTextureId);
workerThreadWait();
}
@@ -1040,7 +1058,7 @@ public:
m_changeTextureWidth = width;
m_changeTextureHeight = height;
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperChangeTexture);
+ setSharedParam(1, eGUIHelperChangeTexture);
workerThreadWait();
}
@@ -1054,7 +1072,7 @@ public:
m_rgbaColor[2] = rgbaColor[2];
m_rgbaColor[3] = rgbaColor[3];
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperChangeGraphicsInstanceRGBAColor);
+ setSharedParam(1, eGUIHelperChangeGraphicsInstanceRGBAColor);
workerThreadWait();
}
@@ -1066,21 +1084,11 @@ public:
m_graphicsInstanceFlagsInstanceUid = instanceUid;
m_graphicsInstanceFlags = flags;
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperChangeGraphicsInstanceFlags);
+ setSharedParam(1, eGUIHelperChangeGraphicsInstanceFlags);
workerThreadWait();
}
- double m_rgbBackground[3];
- virtual void setBackgroundColor(const double rgbBackground[3])
- {
- m_rgbBackground[0] = rgbBackground[0];
- m_rgbBackground[1] = rgbBackground[1];
- m_rgbBackground[2] = rgbBackground[2];
- m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperSetRgbBackground);
- workerThreadWait();
- this->getRenderInterface()->setBackgroundColor(rgbBackground);
- }
+
int m_graphicsInstanceChangeScaling;
@@ -1092,7 +1100,7 @@ public:
m_baseScaling[1] = scaling[1];
m_baseScaling[2] = scaling[2];
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperChangeGraphicsInstanceScaling);
+ setSharedParam(1, eGUIHelperChangeGraphicsInstanceScaling);
workerThreadWait();
}
@@ -1105,7 +1113,7 @@ public:
m_specularColor[1] = specularColor[1];
m_specularColor[2] = specularColor[2];
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperChangeGraphicsInstanceSpecularColor);
+ setSharedParam(1, eGUIHelperChangeGraphicsInstanceSpecularColor);
workerThreadWait();
}
@@ -1156,7 +1164,7 @@ public:
#ifdef SYNC_CAMERA_USING_GUI_CS
m_csGUI->unlock();
#else
- m_cs->setSharedParam(1, eGUIHelperResetCamera);
+ setSharedParam(1, eGUIHelperResetCamera);
workerThreadWait();
m_childGuiHelper->resetCamera(camDist, yaw, pitch, camPosX, camPosY, camPosZ);
#endif //SYNC_CAMERA_USING_GUI_CS
@@ -1204,7 +1212,7 @@ public:
m_destinationHeight = destinationHeight;
m_numPixelsCopied = numPixelsCopied;
- m_cs->setSharedParam(1, eGUIHelperCopyCameraImageData);
+ setSharedParam(1, eGUIHelperCopyCameraImageData);
workerThreadWait();
}
@@ -1231,7 +1239,7 @@ public:
m_destinationHeight = destinationHeight;
m_numPixelsCopied = numPixelsCopied;
- m_cs->setSharedParam(1, eGUIHelperDisplayCameraImageData);
+ setSharedParam(1, eGUIHelperDisplayCameraImageData);
workerThreadWait();
}
@@ -1257,7 +1265,7 @@ public:
{
m_dynamicsWorld = rbWorld;
m_cs->lock();
- m_cs->setSharedParam(1, eGUIHelperAutogenerateGraphicsObjects);
+ setSharedParam(1, eGUIHelperAutogenerateGraphicsObjects);
workerThreadWait();
}
@@ -1310,7 +1318,7 @@ public:
m_tmpText.m_textOrientation[3] = orientation[3];
m_cs->lock();
- m_cs->setSharedParam(1, eGUIUserDebugAddText);
+ setSharedParam(1, eGUIUserDebugAddText);
m_resultUserDebugTextUid = -1;
workerThreadWait();
@@ -1343,7 +1351,7 @@ public:
m_tmpParam.m_itemUniqueId = m_uidGenerator++;
m_cs->lock();
- m_cs->setSharedParam(1, eGUIUserDebugAddParameter);
+ setSharedParam(1, eGUIUserDebugAddParameter);
m_userDebugParamUid = -1;
workerThreadWait();
@@ -1398,7 +1406,7 @@ public:
{
m_cs->lock();
- m_cs->setSharedParam(1, eGUIUserDebugAddLine);
+ setSharedParam(1, eGUIUserDebugAddLine);
m_resultDebugLineUid = -1;
workerThreadWait();
}
@@ -1411,20 +1419,20 @@ public:
{
m_removeDebugItemUid = debugItemUniqueId;
m_cs->lock();
- m_cs->setSharedParam(1, eGUIUserDebugRemoveItem);
+ setSharedParam(1, eGUIUserDebugRemoveItem);
workerThreadWait();
}
virtual void removeAllUserDebugItems()
{
m_cs->lock();
- m_cs->setSharedParam(1, eGUIUserDebugRemoveAllItems);
+ setSharedParam(1, eGUIUserDebugRemoveAllItems);
workerThreadWait();
}
virtual void removeAllUserParameters()
{
m_cs->lock();
- m_cs->setSharedParam(1, eGUIUserDebugRemoveAllParameters);
+ setSharedParam(1, eGUIUserDebugRemoveAllParameters);
workerThreadWait();
}
@@ -1436,7 +1444,7 @@ public:
{
m_cs->lock();
m_mp4FileName = mp4FileName;
- m_cs->setSharedParam(1, eGUIDumpFramesToVideo);
+ setSharedParam(1, eGUIDumpFramesToVideo);
workerThreadWait();
m_mp4FileName = 0;
}
@@ -1909,8 +1917,10 @@ void PhysicsServerExample::initPhysics()
}
}
m_args[0].m_cs->lock();
+ m_args[0].m_csGUI->lock();
m_args[0].m_cs->setSharedParam(1, eGUIHelperIdle);
- m_args[0].m_cs->unlock();
+ m_args[0].m_csGUI->unlock();
+ m_args[0].m_cs->unlock();
m_args[0].m_cs2->lock();
{
@@ -2075,14 +2085,22 @@ void PhysicsServerExample::updateGraphics()
case eGUIHelperRegisterGraphicsShape:
{
B3_PROFILE("eGUIHelperRegisterGraphicsShape");
- m_multiThreadedHelper->m_shapeIndex = m_multiThreadedHelper->m_childGuiHelper->registerGraphicsShape(
+ int shapeIndex = m_multiThreadedHelper->m_childGuiHelper->registerGraphicsShape(
m_multiThreadedHelper->m_vertices,
m_multiThreadedHelper->m_numvertices,
m_multiThreadedHelper->m_indices,
m_multiThreadedHelper->m_numIndices,
m_multiThreadedHelper->m_primitiveType,
m_multiThreadedHelper->m_textureId);
- m_multiThreadedHelper->mainThreadRelease();
+
+ m_multiThreadedHelper->getCriticalSectionGUI()->lock();
+ m_multiThreadedHelper->m_shapeIndex = shapeIndex;
+ m_multiThreadedHelper->getCriticalSectionGUI()->unlock();
+
+
+ m_multiThreadedHelper->mainThreadRelease();
+
+
break;
}
@@ -2294,13 +2312,6 @@ void PhysicsServerExample::updateGraphics()
break;
}
- case eGUIHelperSetRgbBackground:
- {
- m_multiThreadedHelper->m_childGuiHelper->setBackgroundColor(m_multiThreadedHelper->m_rgbBackground);
- m_multiThreadedHelper->mainThreadRelease();
- break;
- }
-
case eGUIHelperChangeGraphicsInstanceScaling:
{
B3_PROFILE("eGUIHelperChangeGraphicsInstanceScaling");