PosixThreadSupport.h

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2007 Erwin Coumans  http://bulletphysics.com
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
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 // PosixThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication
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         // placeholder, until libspe2 support is there
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; //for taskDesc etc
00054                 void*   m_lsMemory; //initialized using PosixLocalStoreMemorySetupFunc
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

Generated on Mon Feb 15 22:17:08 2010 for Bullet Collision Detection & Physics Library by  doxygen 1.6.1