fix some race conditions
This commit is contained in:
@@ -27,7 +27,6 @@ bool gEnableRendering = true;
|
|||||||
bool gActivedVRRealTimeSimulation = false;
|
bool gActivedVRRealTimeSimulation = false;
|
||||||
|
|
||||||
bool gEnableSyncPhysicsRendering = true;
|
bool gEnableSyncPhysicsRendering = true;
|
||||||
bool gEnableUpdateDebugDrawLines = true;
|
|
||||||
static int gCamVisualizerWidth = 228;
|
static int gCamVisualizerWidth = 228;
|
||||||
static int gCamVisualizerHeight = 192;
|
static int gCamVisualizerHeight = 192;
|
||||||
|
|
||||||
@@ -177,6 +176,7 @@ struct MotionArgs
|
|||||||
{
|
{
|
||||||
MotionArgs()
|
MotionArgs()
|
||||||
: m_debugDrawFlags(0),
|
: m_debugDrawFlags(0),
|
||||||
|
m_enableUpdateDebugDrawLines(true),
|
||||||
m_physicsServerPtr(0)
|
m_physicsServerPtr(0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_VR_CONTROLLERS; i++)
|
for (int i = 0; i < MAX_VR_CONTROLLERS; i++)
|
||||||
@@ -201,7 +201,7 @@ struct MotionArgs
|
|||||||
b3CriticalSection* m_csGUI;
|
b3CriticalSection* m_csGUI;
|
||||||
|
|
||||||
int m_debugDrawFlags;
|
int m_debugDrawFlags;
|
||||||
|
bool m_enableUpdateDebugDrawLines;
|
||||||
btAlignedObjectArray<MyMouseCommand> m_mouseCommands;
|
btAlignedObjectArray<MyMouseCommand> m_mouseCommands;
|
||||||
|
|
||||||
b3VRControllerEvent m_vrControllerEvents[MAX_VR_CONTROLLERS];
|
b3VRControllerEvent m_vrControllerEvents[MAX_VR_CONTROLLERS];
|
||||||
@@ -424,13 +424,13 @@ void MotionThreadFunc(void* userPtr, void* lsMemory)
|
|||||||
args->m_physicsServerPtr->stepSimulationRealTime(deltaTimeInSeconds, args->m_sendVrControllerEvents, numSendVrControllers, keyEvents, args->m_sendKeyEvents.size(), mouseEvents, args->m_sendMouseEvents.size());
|
args->m_physicsServerPtr->stepSimulationRealTime(deltaTimeInSeconds, args->m_sendVrControllerEvents, numSendVrControllers, keyEvents, args->m_sendKeyEvents.size(), mouseEvents, args->m_sendMouseEvents.size());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
if (gEnableUpdateDebugDrawLines)
|
args->m_csGUI->lock();
|
||||||
|
if (args->m_enableUpdateDebugDrawLines)
|
||||||
{
|
{
|
||||||
args->m_csGUI->lock();
|
|
||||||
args->m_physicsServerPtr->physicsDebugDraw(args->m_debugDrawFlags);
|
args->m_physicsServerPtr->physicsDebugDraw(args->m_debugDrawFlags);
|
||||||
gEnableUpdateDebugDrawLines = false;
|
args->m_enableUpdateDebugDrawLines = false;
|
||||||
args->m_csGUI->unlock();
|
|
||||||
}
|
}
|
||||||
|
args->m_csGUI->unlock();
|
||||||
}
|
}
|
||||||
deltaTimeInSeconds = 0;
|
deltaTimeInSeconds = 0;
|
||||||
}
|
}
|
||||||
@@ -1763,7 +1763,6 @@ void PhysicsServerExample::initPhysics()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_args[0].m_cs->lock();
|
m_args[0].m_cs->lock();
|
||||||
m_args[0].m_cs->setSharedParam(1, eGUIHelperIdle);
|
m_args[0].m_cs->setSharedParam(1, eGUIHelperIdle);
|
||||||
m_args[0].m_cs->unlock();
|
m_args[0].m_cs->unlock();
|
||||||
@@ -2845,7 +2844,7 @@ void PhysicsServerExample::physicsDebugDraw(int debugDrawFlags)
|
|||||||
//draw stuff and flush?
|
//draw stuff and flush?
|
||||||
this->m_multiThreadedHelper->m_debugDraw->drawDebugDrawerLines();
|
this->m_multiThreadedHelper->m_debugDraw->drawDebugDrawerLines();
|
||||||
m_args[0].m_debugDrawFlags = debugDrawFlags;
|
m_args[0].m_debugDrawFlags = debugDrawFlags;
|
||||||
gEnableUpdateDebugDrawLines = true;
|
m_args[0].m_enableUpdateDebugDrawLines = true;
|
||||||
m_args[0].m_csGUI->unlock();
|
m_args[0].m_csGUI->unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,12 +198,10 @@ static void* threadFunction(void* argument)
|
|||||||
status->m_status = 3;
|
status->m_status = 3;
|
||||||
status->m_cs->unlock();
|
status->m_cs->unlock();
|
||||||
checkPThreadFunction(sem_post(status->m_mainSemaphore));
|
checkPThreadFunction(sem_post(status->m_mainSemaphore));
|
||||||
printf("Thread with taskId %i exiting\n", status->m_taskId);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Thread TERMINATED\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +270,6 @@ void btThreadSupportPosix::waitForAllTasks()
|
|||||||
void btThreadSupportPosix::startThreads(const ConstructionInfo& threadConstructionInfo)
|
void btThreadSupportPosix::startThreads(const ConstructionInfo& threadConstructionInfo)
|
||||||
{
|
{
|
||||||
m_numThreads = btGetNumHardwareThreads() - 1; // main thread exists already
|
m_numThreads = btGetNumHardwareThreads() - 1; // main thread exists already
|
||||||
printf("%s creating %i threads.\n", __FUNCTION__, m_numThreads);
|
|
||||||
m_activeThreadStatus.resize(m_numThreads);
|
m_activeThreadStatus.resize(m_numThreads);
|
||||||
m_startedThreadsMask = 0;
|
m_startedThreadsMask = 0;
|
||||||
|
|
||||||
@@ -281,7 +278,6 @@ void btThreadSupportPosix::startThreads(const ConstructionInfo& threadConstructi
|
|||||||
|
|
||||||
for (int i = 0; i < m_numThreads; i++)
|
for (int i = 0; i < m_numThreads; i++)
|
||||||
{
|
{
|
||||||
printf("starting thread %d\n", i);
|
|
||||||
btThreadStatus& threadStatus = m_activeThreadStatus[i];
|
btThreadStatus& threadStatus = m_activeThreadStatus[i];
|
||||||
threadStatus.startSemaphore = createSem("threadLocal");
|
threadStatus.startSemaphore = createSem("threadLocal");
|
||||||
threadStatus.m_userPtr = 0;
|
threadStatus.m_userPtr = 0;
|
||||||
@@ -294,7 +290,6 @@ void btThreadSupportPosix::startThreads(const ConstructionInfo& threadConstructi
|
|||||||
threadStatus.threadUsed = 0;
|
threadStatus.threadUsed = 0;
|
||||||
checkPThreadFunction(pthread_create(&threadStatus.thread, NULL, &threadFunction, (void*)&threadStatus));
|
checkPThreadFunction(pthread_create(&threadStatus.thread, NULL, &threadFunction, (void*)&threadStatus));
|
||||||
|
|
||||||
printf("started thread %d \n", i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,20 +299,15 @@ void btThreadSupportPosix::stopThreads()
|
|||||||
for (size_t t = 0; t < size_t(m_activeThreadStatus.size()); ++t)
|
for (size_t t = 0; t < size_t(m_activeThreadStatus.size()); ++t)
|
||||||
{
|
{
|
||||||
btThreadStatus& threadStatus = m_activeThreadStatus[t];
|
btThreadStatus& threadStatus = m_activeThreadStatus[t];
|
||||||
printf("%s: Thread %i used: %ld\n", __FUNCTION__, int(t), threadStatus.threadUsed);
|
|
||||||
|
|
||||||
threadStatus.m_userPtr = 0;
|
threadStatus.m_userPtr = 0;
|
||||||
checkPThreadFunction(sem_post(threadStatus.startSemaphore));
|
checkPThreadFunction(sem_post(threadStatus.startSemaphore));
|
||||||
checkPThreadFunction(sem_wait(m_mainSemaphore));
|
checkPThreadFunction(sem_wait(m_mainSemaphore));
|
||||||
|
|
||||||
printf("destroy semaphore\n");
|
|
||||||
destroySem(threadStatus.startSemaphore);
|
destroySem(threadStatus.startSemaphore);
|
||||||
printf("semaphore destroyed\n");
|
|
||||||
checkPThreadFunction(pthread_join(threadStatus.thread, 0));
|
checkPThreadFunction(pthread_join(threadStatus.thread, 0));
|
||||||
}
|
}
|
||||||
printf("destroy main semaphore\n");
|
|
||||||
destroySem(m_mainSemaphore);
|
destroySem(m_mainSemaphore);
|
||||||
printf("main semaphore destroyed\n");
|
|
||||||
m_activeThreadStatus.clear();
|
m_activeThreadStatus.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user