Allow InProcessExampleBrowser to use a malloc allocated memory block, instead of system shared memory.

Make shared memory client/server a bit more robust, in case the server is terminated early.
This commit is contained in:
erwincoumans
2016-03-10 14:36:46 -08:00
parent 40a9b8cea0
commit efbb1edecc
19 changed files with 186 additions and 23 deletions

View File

@@ -24,6 +24,7 @@ SET(App_ExampleBrowser_SRCS
../SharedMemory/PhysicsClientExample.cpp
../SharedMemory/PosixSharedMemory.cpp
../SharedMemory/Win32SharedMemory.cpp
../SharedMemory/InProcessMemory.cpp
../SharedMemory/PhysicsServerSharedMemory.cpp
../SharedMemory/PhysicsDirect.cpp
../SharedMemory/PhysicsDirect.h

View File

@@ -14,6 +14,7 @@
#include "ExampleEntries.h"
#include "Bullet3Common/b3Logging.h"
#include "../SharedMemory/InProcessMemory.h"
void ExampleBrowserThreadFunc(void* userPtr,void* lsMemory);
void* ExampleBrowserMemoryFunc();
@@ -65,6 +66,7 @@ struct ExampleBrowserArgs
struct ExampleBrowserThreadLocalStorage
{
SharedMemoryInterface* m_sharedMem;
int threadId;
};
@@ -92,7 +94,9 @@ void ExampleBrowserThreadFunc(void* userPtr,void* lsMemory)
ExampleEntries examples;
examples.initExampleEntries();
ExampleBrowserInterface* exampleBrowser = new DefaultBrowser(&examples);
DefaultBrowser* exampleBrowser = new DefaultBrowser(&examples);
exampleBrowser->setSharedMemoryInterface(localStorage->m_sharedMem);
bool init = exampleBrowser->init(args->m_argc,args->m_argv);
clock.reset();
if (init)
@@ -139,6 +143,7 @@ struct btInProcessExampleBrowserInternalData
{
ExampleBrowserArgs m_args;
b3ThreadSupportInterface* m_threadSupport;
SharedMemoryInterface* m_sharedMem;
};
@@ -146,6 +151,7 @@ btInProcessExampleBrowserInternalData* btCreateInProcessExampleBrowser(int argc,
{
btInProcessExampleBrowserInternalData* data = new btInProcessExampleBrowserInternalData;
data->m_sharedMem = new InProcessMemory;
int numThreads = 1;
int i;
@@ -163,6 +169,7 @@ btInProcessExampleBrowserInternalData* btCreateInProcessExampleBrowser(int argc,
ExampleBrowserThreadLocalStorage* storage = (ExampleBrowserThreadLocalStorage*) data->m_threadSupport->getThreadLocalMemory(i);
b3Assert(storage);
storage->threadId = i;
storage->m_sharedMem = data->m_sharedMem;
}
@@ -189,6 +196,11 @@ bool btIsExampleBrowserTerminated(btInProcessExampleBrowserInternalData* data)
return (data->m_args.m_cs->getSharedParam(0)==eExampleBrowserHasTerminated);
}
SharedMemoryInterface* btGetSharedMemoryInterface(btInProcessExampleBrowserInternalData* data)
{
return data->m_sharedMem;
}
void btShutDownExampleBrowser(btInProcessExampleBrowserInternalData* data)
{
int numActiveThreads = 1;
@@ -213,6 +225,7 @@ void btShutDownExampleBrowser(btInProcessExampleBrowserInternalData* data)
printf("stopping threads\n");
delete data->m_threadSupport;
delete data->m_sharedMem;
delete data;
}

View File

@@ -9,5 +9,7 @@ bool btIsExampleBrowserTerminated(btInProcessExampleBrowserInternalData* data);
void btShutDownExampleBrowser(btInProcessExampleBrowserInternalData* data);
class SharedMemoryInterface* btGetSharedMemoryInterface(btInProcessExampleBrowserInternalData* data);
#endif //IN_PROCESS_EXAMPLE_BROWSER_H

View File

@@ -49,6 +49,7 @@ static CommonParameterInterface* s_parameterInterface=0;
static CommonRenderInterface* s_instancingRenderer=0;
static OpenGLGuiHelper* s_guiHelper=0;
static MyProfileWindow* s_profWindow =0;
static SharedMemoryInterface* sSharedMem = 0;
#define DEMO_SELECTION_COMBOBOX 13
const char* startFileName = "0_Bullet3Demo.txt";
@@ -326,6 +327,7 @@ void selectDemo(int demoIndex)
int option = gAllExamples->getExampleOption(demoIndex);
s_guiHelper= new OpenGLGuiHelper(s_app, sUseOpenGL2);
CommonExampleOptions options(s_guiHelper, option);
options.m_sharedMem = sSharedMem;
sCurrentDemo = (*func)(options);
if (sCurrentDemo)
{
@@ -1078,3 +1080,8 @@ void OpenGLExampleBrowser::update(float deltaTime)
gui->forceUpdateScrollBars();
}
void OpenGLExampleBrowser::setSharedMemoryInterface(class SharedMemoryInterface* sharedMem)
{
sSharedMem = sharedMem;
}

View File

@@ -17,6 +17,8 @@ public:
virtual void update(float deltaTime);
virtual bool requestedExit();
virtual void setSharedMemoryInterface(class SharedMemoryInterface* sharedMem);
};

View File

@@ -58,6 +58,7 @@
"../SharedMemory/PhysicsClient.cpp",
"../SharedMemory/PosixSharedMemory.cpp",
"../SharedMemory/Win32SharedMemory.cpp",
"../SharedMemory/InProcessMemory.cpp",
"../SharedMemory/PhysicsDirect.cpp",
"../SharedMemory/PhysicsDirect.h",
"../SharedMemory/PhysicsDirectC_API.cpp",