fix posix memory release issues

fix compile problems on Mac OSX
reduce shared memory size on Mac (>512*1024 fails to allocate)
This commit is contained in:
Erwin Coumans
2018-05-02 15:39:16 -07:00
parent 1f6afcda30
commit 4a8ad1a54e
9 changed files with 45 additions and 9 deletions

View File

@@ -21,7 +21,7 @@
void SampleThreadFunc(void* userPtr,void* lsMemory);
void* SamplelsMemoryFunc();
void SamplelsMemoryReleaseFunc(void* ptr);
#include <stdio.h>
//#include "BulletMultiThreaded/PlatformDefinitions.h"
@@ -34,6 +34,7 @@ b3ThreadSupportInterface* createThreadSupport(int numThreads)
b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads",
SampleThreadFunc,
SamplelsMemoryFunc,
SamplelsMemoryReleaseFunc,
numThreads);
b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo);
@@ -47,7 +48,7 @@ b3ThreadSupportInterface* createThreadSupport(int numThreads)
b3ThreadSupportInterface* createThreadSupport(int numThreads)
{
b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",SampleThreadFunc,SamplelsMemoryFunc,numThreads);
b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",SampleThreadFunc,SamplelsMemoryFunc,SamplelsMemoryReleaseFunc,numThreads);
b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo);
return threadSupport;
@@ -155,7 +156,11 @@ void* SamplelsMemoryFunc()
return new SampleThreadLocalStorage;
}
void SamplelsMemoryReleaseFunc(void* ptr)
{
SampleThreadLocalStorage* p = (SampleThreadLocalStorage*) ptr;
delete p;
}

View File

@@ -251,7 +251,8 @@ void b3PosixThreadSupport::startThreads(ThreadConstructionInfo& threadConstructi
spuStatus.m_mainSemaphore = m_mainSemaphore;
spuStatus.m_lsMemory = threadConstructionInfo.m_lsMemoryFunc();
spuStatus.m_userThreadFunc = threadConstructionInfo.m_userThreadFunc;
spuStatus.threadUsed = 0;
spuStatus.m_lsMemoryReleaseFunc = threadConstructionInfo.m_lsMemoryReleaseFunc;
spuStatus.threadUsed = 0;
printf("started thread %d \n",i);
@@ -277,7 +278,12 @@ void b3PosixThreadSupport::stopThreads()
destroySem(spuStatus.startSemaphore);
printf("semaphore destroyed\n");
checkPThreadFunction(pthread_join(spuStatus.thread,0));
delete spuStatus.m_lsMemory;
if (spuStatus.m_lsMemoryReleaseFunc)
{
spuStatus.m_lsMemoryReleaseFunc( spuStatus.m_lsMemory);
}
}
printf("destroy main semaphore\n");
destroySem(m_mainSemaphore);

View File

@@ -35,6 +35,7 @@ subject to the following restrictions:
typedef void (*b3PosixThreadFunc)(void* userPtr,void* lsMemory);
typedef void* (*b3PosixlsMemorySetupFunc)();
typedef void (*b3PosixlsMemoryReleaseFunc)(void* ptr);
// b3PosixThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication
class b3PosixThreadSupport : public b3ThreadSupportInterface
@@ -55,6 +56,8 @@ public:
b3PosixThreadFunc m_userThreadFunc;
void* m_userPtr; //for taskDesc etc
b3PosixlsMemoryReleaseFunc m_lsMemoryReleaseFunc;
void* m_lsMemory; //initialized using PosixLocalStoreMemorySetupFunc
pthread_t thread;
@@ -83,12 +86,14 @@ public:
ThreadConstructionInfo(const char* uniqueName,
b3PosixThreadFunc userThreadFunc,
b3PosixlsMemorySetupFunc lsMemoryFunc,
b3PosixlsMemoryReleaseFunc lsMemoryReleaseFunc,
int numThreads=1,
int threadStackSize=65535
)
:m_uniqueName(uniqueName),
m_userThreadFunc(userThreadFunc),
m_lsMemoryFunc(lsMemoryFunc),
m_lsMemoryReleaseFunc(lsMemoryReleaseFunc),
m_numThreads(numThreads),
m_threadStackSize(threadStackSize)
{
@@ -98,6 +103,8 @@ public:
const char* m_uniqueName;
b3PosixThreadFunc m_userThreadFunc;
b3PosixlsMemorySetupFunc m_lsMemoryFunc;
b3PosixlsMemoryReleaseFunc m_lsMemoryReleaseFunc;
int m_numThreads;
int m_threadStackSize;