25 #define checkPThreadFunction(returnValue) \
26 if(0 != returnValue) { \
27 printf("PThread problem at line %i in file %s: %i %d\n", __LINE__, __FILE__, returnValue, errno); \
46 #if (defined (__APPLE__))
47 #define NAMED_SEMAPHORES
55 static int semCount = 0;
56 #ifdef NAMED_SEMAPHORES
59 snprintf(name, 32,
"/%s-%d-%4.4d", baseName, getpid(), semCount++);
60 sem_t* tempSem = sem_open(name, O_CREAT, 0600, 0);
62 if (tempSem != reinterpret_cast<sem_t *>(SEM_FAILED))
73 sem_t* tempSem =
new sem_t;
81 #ifdef NAMED_SEMAPHORES
112 printf(
"Thread with taskId %i exiting\n",status->
m_taskId);
118 printf(
"Thread TERMINATED\n");
142 spuStatus.
m_userPtr = (
void*)uiArgument0;
199 printf(
"%s creating %i threads.\n", __FUNCTION__, threadConstructionInfo.
m_numThreads);
205 for (
int i=0;i < threadConstructionInfo.
m_numThreads;i++)
207 printf(
"starting thread %d\n",i);
224 printf(
"started thread %d \n",i);
241 printf(
"%s: Thread %i used: %ld\n", __FUNCTION__,
int(t), spuStatus.
threadUsed);
247 printf(
"destroy semaphore\n");
249 printf(
"semaphore destroyed\n");
253 printf(
"destroy main semaphore\n");
255 printf(
"main semaphore destroyed\n");
266 pthread_mutex_init(&
m_mutex, NULL);
270 pthread_mutex_destroy(&
m_mutex);
290 pthread_mutex_unlock(&
m_mutex);
295 #if defined(_POSIX_BARRIERS) && (_POSIX_BARRIERS - 20012L) >= 0
299 pthread_barrier_t m_barr;
305 pthread_barrier_destroy(&m_barr);
310 int rc = pthread_barrier_wait(&m_barr);
311 if(rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD)
313 printf(
"Could not wait on barrier\n");
319 int result = pthread_barrier_init(&m_barr, NULL, numThreads);
347 pthread_mutex_destroy(&
m_mutex);
348 pthread_cond_destroy(&
m_cond);
358 pthread_cond_broadcast(&
m_cond);
362 pthread_mutex_unlock(&
m_mutex);
369 pthread_mutex_destroy(&
m_mutex);
370 pthread_cond_destroy(&
m_cond);
373 pthread_mutex_init(&
m_mutex,NULL);
374 pthread_cond_init(&
m_cond,NULL);
383 #endif//_POSIX_BARRIERS
408 #endif // USE_PTHREADS
virtual btCriticalSection * createCriticalSection()
PosixlsMemorySetupFunc m_lsMemoryFunc
void startThreads(ThreadConstructionInfo &threadInfo)
static void * threadFunction(void *argument)
virtual void setMaxCount(int numThreads)
virtual void deleteBarrier(btBarrier *barrier)
virtual btBarrier * createBarrier()
virtual ~PosixThreadSupport()
cleanup/shutdown Libspe2
PosixThreadFunc m_userThreadFunc
unsigned int mCommonBuff[32]
static void destroySem(sem_t *semaphore)
PosixThreadFunc m_userThreadFunc
virtual unsigned int getSharedParam(int i)
virtual ~PosixCriticalSection()
virtual int getNumTasks() const
#define ATTRIBUTE_ALIGNED16(a)
virtual void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1)
check for messages from SPUs
PosixThreadSupport(ThreadConstructionInfo &threadConstructionInfo)
#define checkPThreadFunction(returnValue)
virtual void setSharedParam(int i, unsigned int p)
btAlignedObjectArray< btSpuStatus > m_activeSpuStatus
static sem_t * mainSemaphore
virtual int getMaxCount()
static sem_t * createSem(const char *baseName)
virtual void stopSPU()
tell the task scheduler we are done with the SPU tasks
Setup and initialize SPU/CELL/Libspe2.
virtual void deleteCriticalSection(btCriticalSection *criticalSection)
static void barrier(unsigned int a)
virtual void sendRequest(uint32_t uiCommand, ppu_address_t uiArgument0, uint32_t uiArgument1)
send messages to SPUs
#define CMD_GATHER_AND_PROCESS_PAIRLIST
virtual void startSPU()
start the spus (can be called at the beginning of each frame, to make sure that the right SPU program...