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

@@ -18,6 +18,8 @@
void ExampleBrowserThreadFunc(void* userPtr,void* lsMemory); void ExampleBrowserThreadFunc(void* userPtr,void* lsMemory);
void* ExampleBrowserMemoryFunc(); void* ExampleBrowserMemoryFunc();
void ExampleBrowserMemoryReleaseFunc(void* ptr);
#include <stdio.h> #include <stdio.h>
//#include "BulletMultiThreaded/PlatformDefinitions.h" //#include "BulletMultiThreaded/PlatformDefinitions.h"
@@ -42,6 +44,7 @@ static b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThread
b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads", b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads",
ExampleBrowserThreadFunc, ExampleBrowserThreadFunc,
ExampleBrowserMemoryFunc, ExampleBrowserMemoryFunc,
ExampleBrowserMemoryReleaseFunc,
numThreads); numThreads);
b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo); b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo);
@@ -56,7 +59,7 @@ static b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThread
b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThreads) b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThreads)
{ {
b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",ExampleBrowserThreadFunc,ExampleBrowserMemoryFunc,numThreads); b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",ExampleBrowserThreadFunc,ExampleBrowserMemoryFunc,ExampleBrowserMemoryReleaseFunc,numThreads);
b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo); b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo);
return threadSupport; return threadSupport;
@@ -303,6 +306,12 @@ void* ExampleBrowserMemoryFunc()
return new ExampleBrowserThreadLocalStorage; return new ExampleBrowserThreadLocalStorage;
} }
void ExampleBrowserMemoryReleaseFunc(void* ptr)
{
ExampleBrowserThreadLocalStorage* p = (ExampleBrowserThreadLocalStorage*) ptr;
delete ptr;
}

View File

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

View File

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

View File

@@ -11,6 +11,8 @@
#include "../MultiThreading/b3ThreadSupportInterface.h" #include "../MultiThreading/b3ThreadSupportInterface.h"
void UDPThreadFunc(void* userPtr, void* lsMemory); void UDPThreadFunc(void* userPtr, void* lsMemory);
void* UDPlsMemoryFunc(); void* UDPlsMemoryFunc();
void UDPlsMemoryReleaseFunc(void* ptr);
bool gVerboseNetworkMessagesClient = false; bool gVerboseNetworkMessagesClient = false;
#ifndef _WIN32 #ifndef _WIN32
@@ -21,6 +23,7 @@ b3ThreadSupportInterface* createUDPThreadSupport(int numThreads)
b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("UDPThread", b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("UDPThread",
UDPThreadFunc, UDPThreadFunc,
UDPlsMemoryFunc, UDPlsMemoryFunc,
UDPlsMemoryReleaseFunc,
numThreads); numThreads);
b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo); b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo);
@@ -34,7 +37,7 @@ b3ThreadSupportInterface* createUDPThreadSupport(int numThreads)
b3ThreadSupportInterface* createUDPThreadSupport(int numThreads) b3ThreadSupportInterface* createUDPThreadSupport(int numThreads)
{ {
b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("UDPThread", UDPThreadFunc, UDPlsMemoryFunc, numThreads); b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("UDPThread", UDPThreadFunc, UDPlsMemoryFunc,UDPlsMemoryReleaseFunc, numThreads);
b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo); b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo);
return threadSupport; return threadSupport;
@@ -436,6 +439,11 @@ void* UDPlsMemoryFunc()
return new UDPThreadLocalStorage; return new UDPThreadLocalStorage;
} }
void UDPlsMemoryReleaseFunc(void* ptr)
{
UDPThreadLocalStorage* p = (UDPThreadLocalStorage*) ptr;
delete p;
}

View File

@@ -92,6 +92,7 @@ static void saveCurrentSettingsVR(const btVector3& VRTeleportPos1)
bool gDebugRenderToggle = false; bool gDebugRenderToggle = false;
void MotionThreadFunc(void* userPtr,void* lsMemory); void MotionThreadFunc(void* userPtr,void* lsMemory);
void* MotionlsMemoryFunc(); void* MotionlsMemoryFunc();
void MotionlsMemoryReleaseFunc(void* ptr);
#define MAX_MOTION_NUM_THREADS 1 #define MAX_MOTION_NUM_THREADS 1
enum enum
{ {
@@ -150,6 +151,7 @@ b3ThreadSupportInterface* createMotionThreadSupport(int numThreads)
b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("MotionThreads", b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("MotionThreads",
MotionThreadFunc, MotionThreadFunc,
MotionlsMemoryFunc, MotionlsMemoryFunc,
MotionlsMemoryReleaseFunc,
numThreads); numThreads);
b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo); b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo);
@@ -163,7 +165,7 @@ b3ThreadSupportInterface* createMotionThreadSupport(int numThreads)
b3ThreadSupportInterface* createMotionThreadSupport(int numThreads) b3ThreadSupportInterface* createMotionThreadSupport(int numThreads)
{ {
b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("MotionThreads",MotionThreadFunc,MotionlsMemoryFunc,numThreads); b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("MotionThreads",MotionThreadFunc,MotionlsMemoryFunc,MotionlsMemoryReleaseFunc,numThreads);
b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo); b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo);
return threadSupport; return threadSupport;
@@ -486,6 +488,12 @@ void* MotionlsMemoryFunc()
return new MotionThreadLocalStorage; return new MotionThreadLocalStorage;
} }
void MotionlsMemoryReleaseFunc(void* ptr)
{
MotionThreadLocalStorage* p = (MotionThreadLocalStorage*) ptr;
delete p;
}
struct UserDebugDrawLine struct UserDebugDrawLine