SequentialThreadSupport.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 #include "LinearMath/btScalar.h"
00017 #include "PlatformDefinitions.h"
00018 
00019 
00020 #ifndef BT_SEQUENTIAL_THREAD_SUPPORT_H
00021 #define BT_SEQUENTIAL_THREAD_SUPPORT_H
00022 
00023 #include "LinearMath/btAlignedObjectArray.h"
00024 
00025 #include "btThreadSupportInterface.h"
00026 
00027 typedef void (*SequentialThreadFunc)(void* userPtr,void* lsMemory);
00028 typedef void* (*SequentiallsMemorySetupFunc)();
00029 
00030 
00031 
00034 class SequentialThreadSupport : public btThreadSupportInterface 
00035 {
00036 public:
00037         struct  btSpuStatus
00038         {
00039                 uint32_t        m_taskId;
00040                 uint32_t        m_commandId;
00041                 uint32_t        m_status;
00042 
00043                 SequentialThreadFunc    m_userThreadFunc;
00044 
00045                 void*   m_userPtr; //for taskDesc etc
00046                 void*   m_lsMemory; //initialized using SequentiallsMemorySetupFunc
00047         };
00048 private:
00049         btAlignedObjectArray<btSpuStatus>       m_activeSpuStatus;
00050         btAlignedObjectArray<void*>                     m_completeHandles;      
00051 public:
00052         struct  SequentialThreadConstructionInfo
00053         {
00054                 SequentialThreadConstructionInfo (const char* uniqueName,
00055                                                                         SequentialThreadFunc userThreadFunc,
00056                                                                         SequentiallsMemorySetupFunc     lsMemoryFunc
00057                                                                         )
00058                                                                         :m_uniqueName(uniqueName),
00059                                                                         m_userThreadFunc(userThreadFunc),
00060                                                                         m_lsMemoryFunc(lsMemoryFunc)
00061                 {
00062 
00063                 }
00064 
00065                 const char*                                             m_uniqueName;
00066                 SequentialThreadFunc            m_userThreadFunc;
00067                 SequentiallsMemorySetupFunc     m_lsMemoryFunc;
00068         };
00069 
00070         SequentialThreadSupport(SequentialThreadConstructionInfo& threadConstructionInfo);
00071         virtual ~SequentialThreadSupport();
00072         void    startThreads(SequentialThreadConstructionInfo&  threadInfo);
00074         virtual void sendRequest(uint32_t uiCommand, ppu_address_t uiArgument0, uint32_t uiArgument1);
00076         virtual void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1);
00078         virtual void startSPU();
00080         virtual void stopSPU();
00081 
00082         virtual void setNumTasks(int numTasks);
00083 
00084         virtual int getNumTasks() const
00085         {
00086                 return 1;
00087         }
00088         virtual btBarrier*      createBarrier();
00089 
00090         virtual btCriticalSection* createCriticalSection();
00091         
00092     virtual void deleteBarrier(btBarrier* barrier);
00093     
00094     virtual void deleteCriticalSection(btCriticalSection* criticalSection);
00095 
00096 
00097 };
00098 
00099 #endif //BT_SEQUENTIAL_THREAD_SUPPORT_H
00100