implement barrier/critical section for OSX (PosixThreadSupport)
enable Demos/ThreadingDemo for OSX add cmake build support for VectorAdd_OpenCL for OSX
This commit is contained in:
@@ -12,7 +12,7 @@ SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
|
||||
########################################################
|
||||
|
||||
#currently this demo has only been tested under Windows 32bit
|
||||
IF (WIN32)
|
||||
#IF (WIN32)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
|
||||
@@ -42,4 +42,4 @@ IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppThreadingDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
|
||||
ENDIF(WIN32)
|
||||
#ENDIF(WIN32)
|
||||
|
||||
@@ -20,8 +20,40 @@ subject to the following restrictions:
|
||||
/// June 2010
|
||||
/// New: critical section/barriers and non-blocking pollingn for completion, currently Windows only
|
||||
|
||||
void SampleThreadFunc(void* userPtr,void* lsMemory);
|
||||
void* SamplelsMemoryFunc();
|
||||
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include "BulletMultiThreaded/PosixThreadSupport.h"
|
||||
|
||||
btThreadSupportInterface* createThreadSupport(int numThreads)
|
||||
{
|
||||
PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads",
|
||||
SampleThreadFunc,
|
||||
SamplelsMemoryFunc,
|
||||
numThreads);
|
||||
btThreadSupportInterface* threadSupport = new PosixThreadSupport(constructionInfo);
|
||||
|
||||
return threadSupport;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#elif defined( _WIN32)
|
||||
#include "BulletMultiThreaded/Win32ThreadSupport.h"
|
||||
|
||||
btThreadSupportInterface* createThreadSupport(int numThreads)
|
||||
{
|
||||
Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",SampleThreadFunc,SamplelsMemoryFunc,numThreads);
|
||||
Win32ThreadSupport* threadSupport = new Win32ThreadSupport(threadConstructionInfo);
|
||||
return threadSupport;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
struct SampleArgs
|
||||
{
|
||||
btCriticalSection* m_cs;
|
||||
@@ -64,19 +96,26 @@ void* SamplelsMemoryFunc()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
int numThreads = 4;
|
||||
|
||||
Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",SampleThreadFunc,SamplelsMemoryFunc,numThreads);
|
||||
btThreadSupportInterface* threadSupport = createThreadSupport(numThreads);
|
||||
|
||||
Win32ThreadSupport* threadSupport = new Win32ThreadSupport(threadConstructionInfo);
|
||||
|
||||
threadSupport->startSPU();
|
||||
|
||||
for (int i=0;i<threadSupport->getNumTasks();i++)
|
||||
{
|
||||
SampleThreadLocalStorage* storage = (SampleThreadLocalStorage*)threadSupport->getThreadLocalMemory(i);
|
||||
btAssert(storage);
|
||||
storage->threadId = i;
|
||||
}
|
||||
|
||||
@@ -93,7 +132,7 @@ int main(int argc,char** argv)
|
||||
threadSupport->sendRequest(1, (ppu_address_t) &args, i);
|
||||
}
|
||||
|
||||
bool blockingWait = false;
|
||||
bool blockingWait =true;
|
||||
if (blockingWait)
|
||||
{
|
||||
for (i=0;i<numThreads;i++)
|
||||
@@ -102,6 +141,7 @@ int main(int argc,char** argv)
|
||||
}
|
||||
} else
|
||||
{
|
||||
#if 0
|
||||
int numActiveThreads = numThreads;
|
||||
while (numActiveThreads)
|
||||
{
|
||||
@@ -115,6 +155,7 @@ int main(int argc,char** argv)
|
||||
printf("polling\n");
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
threadSupport->stopSPU();
|
||||
@@ -122,4 +163,4 @@ int main(int argc,char** argv)
|
||||
printf("Press ENTER to quit\n");
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user