expose lsMemory destroy function to release thread memory

This commit is contained in:
erwincoumans
2018-05-02 14:32:43 -07:00
parent 9d66d95b18
commit 3a5f778b70
5 changed files with 40 additions and 5 deletions

View File

@@ -289,6 +289,7 @@ void b3Win32ThreadSupport::startThreads(const Win32ThreadConstructionInfo& threa
threadStatus.m_threadHandle = handle;
threadStatus.m_lsMemory = threadConstructionInfo.m_lsMemoryFunc();
threadStatus.m_userThreadFunc = threadConstructionInfo.m_userThreadFunc;
threadStatus.m_lsMemoryReleaseFunc = threadConstructionInfo.m_lsMemoryReleaseFunc;
printf("started %s thread %d with threadHandle %p\n",threadConstructionInfo.m_uniqueName,i,handle);
@@ -312,9 +313,12 @@ void b3Win32ThreadSupport::stopThreads()
{
WaitForSingleObject(threadStatus.m_eventCompletetHandle, INFINITE);
}
delete threadStatus.m_lsMemory;
if (threadStatus.m_lsMemoryReleaseFunc)
{
threadStatus.m_lsMemoryReleaseFunc(threadStatus.m_lsMemory);
}
threadStatus.m_userPtr = 0;
SetEvent(threadStatus.m_eventStartHandle);
WaitForSingleObject(threadStatus.m_eventCompletetHandle, INFINITE);

View File

@@ -26,6 +26,7 @@ subject to the following restrictions:
typedef void (*b3Win32ThreadFunc)(void* userPtr,void* lsMemory);
typedef void* (*b3Win32lsMemorySetupFunc)();
typedef void (*b3Win32lsMemoryReleaseFunc)(void*);
///b3Win32ThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication
@@ -43,6 +44,8 @@ public:
void* m_userPtr; //for taskDesc etc
void* m_lsMemory; //initialized using Win32LocalStoreMemorySetupFunc
b3Win32lsMemoryReleaseFunc m_lsMemoryReleaseFunc;
void* m_threadHandle; //this one is calling 'Win32ThreadFunc'
void* m_eventStartHandle;
@@ -67,12 +70,14 @@ public:
Win32ThreadConstructionInfo(const char* uniqueName,
b3Win32ThreadFunc userThreadFunc,
b3Win32lsMemorySetupFunc lsMemoryFunc,
b3Win32lsMemoryReleaseFunc 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),
m_priority(0)
@@ -83,6 +88,7 @@ public:
const char* m_uniqueName;
b3Win32ThreadFunc m_userThreadFunc;
b3Win32lsMemorySetupFunc m_lsMemoryFunc;
b3Win32lsMemoryReleaseFunc m_lsMemoryReleaseFunc;
int m_numThreads;
int m_threadStackSize;
int m_priority;