fix some thread sanitizer (read/write integer, should be a harmless warning)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Bullet Continuous Collision Detection and Physics Library
|
Bullet Continuous Collision Detection and Physics Library
|
||||||
Copyright (c) 2003-2018 Erwin Coumans http://bulletphysics.com
|
Copyright (c) 2003-2018 Erwin Coumans http://bulletphysics.com
|
||||||
@@ -72,7 +73,7 @@ public:
|
|||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
//each tread will wait until this signal to start its work
|
//each tread will wait until this signal to start its work
|
||||||
sem_t* startSemaphore;
|
sem_t* startSemaphore;
|
||||||
|
btCriticalSection* m_cs;
|
||||||
// this is a copy of m_mainSemaphore,
|
// this is a copy of m_mainSemaphore,
|
||||||
//each tread will signal once it is finished with its work
|
//each tread will signal once it is finished with its work
|
||||||
sem_t* m_mainSemaphore;
|
sem_t* m_mainSemaphore;
|
||||||
@@ -90,7 +91,7 @@ private:
|
|||||||
void startThreads(const ConstructionInfo& threadInfo);
|
void startThreads(const ConstructionInfo& threadInfo);
|
||||||
void stopThreads();
|
void stopThreads();
|
||||||
int waitForResponse();
|
int waitForResponse();
|
||||||
|
btCriticalSection* m_cs;
|
||||||
public:
|
public:
|
||||||
btThreadSupportPosix(const ConstructionInfo& threadConstructionInfo);
|
btThreadSupportPosix(const ConstructionInfo& threadConstructionInfo);
|
||||||
virtual ~btThreadSupportPosix();
|
virtual ~btThreadSupportPosix();
|
||||||
@@ -119,6 +120,7 @@ public:
|
|||||||
|
|
||||||
btThreadSupportPosix::btThreadSupportPosix(const ConstructionInfo& threadConstructionInfo)
|
btThreadSupportPosix::btThreadSupportPosix(const ConstructionInfo& threadConstructionInfo)
|
||||||
{
|
{
|
||||||
|
m_cs = createCriticalSection();
|
||||||
startThreads(threadConstructionInfo);
|
startThreads(threadConstructionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,6 +128,8 @@ btThreadSupportPosix::btThreadSupportPosix(const ConstructionInfo& threadConstru
|
|||||||
btThreadSupportPosix::~btThreadSupportPosix()
|
btThreadSupportPosix::~btThreadSupportPosix()
|
||||||
{
|
{
|
||||||
stopThreads();
|
stopThreads();
|
||||||
|
deleteCriticalSection(m_cs);
|
||||||
|
m_cs=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (defined(__APPLE__))
|
#if (defined(__APPLE__))
|
||||||
@@ -181,14 +185,18 @@ static void* threadFunction(void* argument)
|
|||||||
{
|
{
|
||||||
btAssert(status->m_status);
|
btAssert(status->m_status);
|
||||||
status->m_userThreadFunc(userPtr);
|
status->m_userThreadFunc(userPtr);
|
||||||
|
status->m_cs->lock();
|
||||||
status->m_status = 2;
|
status->m_status = 2;
|
||||||
|
status->m_cs->unlock();
|
||||||
checkPThreadFunction(sem_post(status->m_mainSemaphore));
|
checkPThreadFunction(sem_post(status->m_mainSemaphore));
|
||||||
status->threadUsed++;
|
status->threadUsed++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//exit Thread
|
//exit Thread
|
||||||
|
status->m_cs->lock();
|
||||||
status->m_status = 3;
|
status->m_status = 3;
|
||||||
|
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);
|
printf("Thread with taskId %i exiting\n", status->m_taskId);
|
||||||
break;
|
break;
|
||||||
@@ -206,7 +214,7 @@ void btThreadSupportPosix::runTask(int threadIndex, void* userData)
|
|||||||
btThreadStatus& threadStatus = m_activeThreadStatus[threadIndex];
|
btThreadStatus& threadStatus = m_activeThreadStatus[threadIndex];
|
||||||
btAssert(threadIndex >= 0);
|
btAssert(threadIndex >= 0);
|
||||||
btAssert(threadIndex < m_activeThreadStatus.size());
|
btAssert(threadIndex < m_activeThreadStatus.size());
|
||||||
|
threadStatus.m_cs = m_cs;
|
||||||
threadStatus.m_commandId = 1;
|
threadStatus.m_commandId = 1;
|
||||||
threadStatus.m_status = 1;
|
threadStatus.m_status = 1;
|
||||||
threadStatus.m_userPtr = userData;
|
threadStatus.m_userPtr = userData;
|
||||||
@@ -231,7 +239,10 @@ int btThreadSupportPosix::waitForResponse()
|
|||||||
|
|
||||||
for (size_t t = 0; t < size_t(m_activeThreadStatus.size()); ++t)
|
for (size_t t = 0; t < size_t(m_activeThreadStatus.size()); ++t)
|
||||||
{
|
{
|
||||||
if (2 == m_activeThreadStatus[t].m_status)
|
m_cs->lock();
|
||||||
|
bool hasFinished = (2 == m_activeThreadStatus[t].m_status);
|
||||||
|
m_cs->unlock();
|
||||||
|
if (hasFinished)
|
||||||
{
|
{
|
||||||
last = t;
|
last = t;
|
||||||
break;
|
break;
|
||||||
@@ -273,15 +284,15 @@ void btThreadSupportPosix::startThreads(const ConstructionInfo& threadConstructi
|
|||||||
printf("starting thread %d\n", 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");
|
||||||
checkPThreadFunction(pthread_create(&threadStatus.thread, NULL, &threadFunction, (void*)&threadStatus));
|
|
||||||
|
|
||||||
threadStatus.m_userPtr = 0;
|
threadStatus.m_userPtr = 0;
|
||||||
|
threadStatus.m_cs = m_cs;
|
||||||
threadStatus.m_taskId = i;
|
threadStatus.m_taskId = i;
|
||||||
threadStatus.m_commandId = 0;
|
threadStatus.m_commandId = 0;
|
||||||
threadStatus.m_status = 0;
|
threadStatus.m_status = 0;
|
||||||
threadStatus.m_mainSemaphore = m_mainSemaphore;
|
threadStatus.m_mainSemaphore = m_mainSemaphore;
|
||||||
threadStatus.m_userThreadFunc = threadConstructionInfo.m_userThreadFunc;
|
threadStatus.m_userThreadFunc = threadConstructionInfo.m_userThreadFunc;
|
||||||
threadStatus.threadUsed = 0;
|
threadStatus.threadUsed = 0;
|
||||||
|
checkPThreadFunction(pthread_create(&threadStatus.thread, NULL, &threadFunction, (void*)&threadStatus));
|
||||||
|
|
||||||
printf("started thread %d \n", i);
|
printf("started thread %d \n", i);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user