fixes in OSX ThreadingDemo / PosixThreadSupport

This commit is contained in:
erwin.coumans
2010-06-29 01:19:03 +00:00
parent 7bfa94b6a3
commit 76a58e1f4e
3 changed files with 33 additions and 12 deletions

View File

@@ -12,8 +12,11 @@ IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Release") SET(CMAKE_BUILD_TYPE "Release")
ENDIF (NOT CMAKE_BUILD_TYPE) ENDIF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG=3")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG=4")
MESSAGE("CMAKE_CXX_FLAGS_DEBUG="+${CMAKE_CXX_FLAGS_DEBUG})
OPTION(USE_DOUBLE_PRECISION "Use double precision" OFF) OPTION(USE_DOUBLE_PRECISION "Use double precision" OFF)
OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" ON) OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" ON)
OPTION(USE_MULTITHREADED_BENCHMARK "Use Multithreaded Benchmark" OFF) OPTION(USE_MULTITHREADED_BENCHMARK "Use Multithreaded Benchmark" OFF)

View File

@@ -67,6 +67,8 @@ struct SampleThreadLocalStorage
void SampleThreadFunc(void* userPtr,void* lsMemory) void SampleThreadFunc(void* userPtr,void* lsMemory)
{ {
printf("thread started\n");
SampleThreadLocalStorage* localStorage = (SampleThreadLocalStorage*) lsMemory; SampleThreadLocalStorage* localStorage = (SampleThreadLocalStorage*) lsMemory;
SampleArgs* args = (SampleArgs*) userPtr; SampleArgs* args = (SampleArgs*) userPtr;
@@ -138,10 +140,11 @@ int main(int argc,char** argv)
for (i=0;i<numThreads;i++) for (i=0;i<numThreads;i++)
{ {
threadSupport->waitForResponse(&arg0,&arg1); threadSupport->waitForResponse(&arg0,&arg1);
printf("finished waiting for response: %d %d\n", arg0,arg1);
} }
} else } else
{ {
#if 0 #if _WIN32
int numActiveThreads = numThreads; int numActiveThreads = numThreads;
while (numActiveThreads) while (numActiveThreads)
{ {
@@ -155,10 +158,15 @@ int main(int argc,char** argv)
printf("polling\n"); printf("polling\n");
} }
}; };
#else
btAssert(0);
printf("non-blocking wait is not supported on this platform\n");
exit(0);
#endif #endif
} }
threadSupport->stopSPU(); printf("stopping threads\n");
delete threadSupport; delete threadSupport;
printf("Press ENTER to quit\n"); printf("Press ENTER to quit\n");
getchar(); getchar();

View File

@@ -48,7 +48,7 @@ PosixThreadSupport::~PosixThreadSupport()
#endif #endif
// this semaphore will signal, if and how many threads are finished with their work // this semaphore will signal, if and how many threads are finished with their work
static sem_t* mainSemaphore; static sem_t* mainSemaphore=0;
static sem_t* createSem(const char* baseName) static sem_t* createSem(const char* baseName)
{ {
@@ -58,9 +58,10 @@ static sem_t* createSem(const char* baseName)
char name[32]; char name[32];
snprintf(name, 32, "/%s-%d-%4.4d", baseName, getpid(), semCount++); snprintf(name, 32, "/%s-%d-%4.4d", baseName, getpid(), semCount++);
sem_t* tempSem = sem_open(name, O_CREAT, 0600, 0); sem_t* tempSem = sem_open(name, O_CREAT, 0600, 0);
if (tempSem != reinterpret_cast<sem_t *>(SEM_FAILED)) if (tempSem != reinterpret_cast<sem_t *>(SEM_FAILED))
{ {
//printf("Created \"%s\" Semaphore %x\n", name, tempSem); // printf("Created \"%s\" Semaphore %p\n", name, tempSem);
} }
else else
{ {
@@ -199,7 +200,8 @@ void PosixThreadSupport::startThreads(ThreadConstructionInfo& threadConstruction
m_activeSpuStatus.resize(threadConstructionInfo.m_numThreads); m_activeSpuStatus.resize(threadConstructionInfo.m_numThreads);
mainSemaphore = createSem("main"); mainSemaphore = createSem("main");
//checkPThreadFunction(sem_wait(mainSemaphore));
for (int i=0;i < threadConstructionInfo.m_numThreads;i++) for (int i=0;i < threadConstructionInfo.m_numThreads;i++)
{ {
printf("starting thread %d\n",i); printf("starting thread %d\n",i);
@@ -233,15 +235,23 @@ void PosixThreadSupport::startSPU()
///tell the task scheduler we are done with the SPU tasks ///tell the task scheduler we are done with the SPU tasks
void PosixThreadSupport::stopSPU() void PosixThreadSupport::stopSPU()
{ {
for(size_t t=0; t < size_t(m_activeSpuStatus.size()); ++t) { for(size_t t=0; t < size_t(m_activeSpuStatus.size()); ++t)
{
btSpuStatus& spuStatus = m_activeSpuStatus[t]; btSpuStatus& spuStatus = m_activeSpuStatus[t];
printf("%s: Thread %i used: %ld\n", __FUNCTION__, int(t), spuStatus.threadUsed); printf("%s: Thread %i used: %ld\n", __FUNCTION__, int(t), spuStatus.threadUsed);
destroySem(spuStatus.startSemaphore);
checkPThreadFunction(pthread_cancel(spuStatus.thread));
}
destroySem(mainSemaphore);
spuStatus.m_userPtr = 0;
checkPThreadFunction(sem_post(spuStatus.startSemaphore));
checkPThreadFunction(sem_wait(mainSemaphore));
printf("destroy semaphore\n");
destroySem(spuStatus.startSemaphore);
printf("semaphore destroyed\n");
checkPThreadFunction(pthread_cancel(spuStatus.thread));
}
printf("destroy main semaphore\n");
destroySem(mainSemaphore);
printf("main semaphore destroyed\n");
m_activeSpuStatus.clear(); m_activeSpuStatus.clear();
} }