PosixThreadSupport.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "LinearMath/btScalar.h"
00018 #include "PlatformDefinitions.h"
00019
00020 #ifdef USE_PTHREADS //platform specific defines are defined in PlatformDefinitions.h
00021 #include <pthread.h>
00022 #include <semaphore.h>
00023
00024 #ifndef POSIX_THREAD_SUPPORT_H
00025 #define POSIX_THREAD_SUPPORT_H
00026
00027 #include "LinearMath/btAlignedObjectArray.h"
00028
00029 #include "btThreadSupportInterface.h"
00030
00031
00032 typedef void (*PosixThreadFunc)(void* userPtr,void* lsMemory);
00033 typedef void* (*PosixlsMemorySetupFunc)();
00034
00035
00036 class PosixThreadSupport : public btThreadSupportInterface
00037 {
00038 public:
00039 typedef enum sStatus {
00040 STATUS_BUSY,
00041 STATUS_READY,
00042 STATUS_FINISHED
00043 } Status;
00044
00045
00046 struct btSpuStatus
00047 {
00048 uint32_t m_taskId;
00049 uint32_t m_commandId;
00050 uint32_t m_status;
00051
00052 PosixThreadFunc m_userThreadFunc;
00053 void* m_userPtr;
00054 void* m_lsMemory;
00055
00056 pthread_t thread;
00057 sem_t* startSemaphore;
00058
00059 unsigned long threadUsed;
00060 };
00061 private:
00062
00063 btAlignedObjectArray<btSpuStatus> m_activeSpuStatus;
00064 public:
00066
00067
00068
00069 struct ThreadConstructionInfo
00070 {
00071 ThreadConstructionInfo(char* uniqueName,
00072 PosixThreadFunc userThreadFunc,
00073 PosixlsMemorySetupFunc lsMemoryFunc,
00074 int numThreads=1,
00075 int threadStackSize=65535
00076 )
00077 :m_uniqueName(uniqueName),
00078 m_userThreadFunc(userThreadFunc),
00079 m_lsMemoryFunc(lsMemoryFunc),
00080 m_numThreads(numThreads),
00081 m_threadStackSize(threadStackSize)
00082 {
00083
00084 }
00085
00086 char* m_uniqueName;
00087 PosixThreadFunc m_userThreadFunc;
00088 PosixlsMemorySetupFunc m_lsMemoryFunc;
00089 int m_numThreads;
00090 int m_threadStackSize;
00091
00092 };
00093
00094 PosixThreadSupport(ThreadConstructionInfo& threadConstructionInfo);
00095
00097 virtual ~PosixThreadSupport();
00098
00099 void startThreads(ThreadConstructionInfo& threadInfo);
00100
00101
00103 virtual void sendRequest(uint32_t uiCommand, ppu_address_t uiArgument0, uint32_t uiArgument1);
00104
00106 virtual void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1);
00107
00109 virtual void startSPU();
00110
00112 virtual void stopSPU();
00113
00114 virtual void setNumTasks(int numTasks) {}
00115
00116 virtual int getNumTasks() const
00117 {
00118 return m_activeSpuStatus.size();
00119 }
00120 };
00121
00122 #endif // POSIX_THREAD_SUPPORT_H
00123
00124 #endif // USE_PTHREADS