SequentialThreadSupport.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 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.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #include "bullet/LinearMath/btScalar.h"
  14. #include "PlatformDefinitions.h"
  15. #ifndef BT_SEQUENTIAL_THREAD_SUPPORT_H
  16. #define BT_SEQUENTIAL_THREAD_SUPPORT_H
  17. #include "bullet/LinearMath/btAlignedObjectArray.h"
  18. #include "btThreadSupportInterface.h"
  19. typedef void (*SequentialThreadFunc)(void* userPtr,void* lsMemory);
  20. typedef void* (*SequentiallsMemorySetupFunc)();
  21. ///The SequentialThreadSupport is a portable non-parallel implementation of the btThreadSupportInterface
  22. ///This is useful for debugging and porting SPU Tasks to other platforms.
  23. class SequentialThreadSupport : public btThreadSupportInterface
  24. {
  25. public:
  26. struct btSpuStatus
  27. {
  28. uint32_t m_taskId;
  29. uint32_t m_commandId;
  30. uint32_t m_status;
  31. SequentialThreadFunc m_userThreadFunc;
  32. void* m_userPtr; //for taskDesc etc
  33. void* m_lsMemory; //initialized using SequentiallsMemorySetupFunc
  34. };
  35. private:
  36. btAlignedObjectArray<btSpuStatus> m_activeSpuStatus;
  37. btAlignedObjectArray<void*> m_completeHandles;
  38. public:
  39. struct SequentialThreadConstructionInfo
  40. {
  41. SequentialThreadConstructionInfo (const char* uniqueName,
  42. SequentialThreadFunc userThreadFunc,
  43. SequentiallsMemorySetupFunc lsMemoryFunc
  44. )
  45. :m_uniqueName(uniqueName),
  46. m_userThreadFunc(userThreadFunc),
  47. m_lsMemoryFunc(lsMemoryFunc)
  48. {
  49. }
  50. const char* m_uniqueName;
  51. SequentialThreadFunc m_userThreadFunc;
  52. SequentiallsMemorySetupFunc m_lsMemoryFunc;
  53. };
  54. SequentialThreadSupport(SequentialThreadConstructionInfo& threadConstructionInfo);
  55. virtual ~SequentialThreadSupport();
  56. void startThreads(SequentialThreadConstructionInfo& threadInfo);
  57. ///send messages to SPUs
  58. virtual void sendRequest(uint32_t uiCommand, ppu_address_t uiArgument0, uint32_t uiArgument1);
  59. ///check for messages from SPUs
  60. virtual void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1);
  61. ///start the spus (can be called at the beginning of each frame, to make sure that the right SPU program is loaded)
  62. virtual void startSPU();
  63. ///tell the task scheduler we are done with the SPU tasks
  64. virtual void stopSPU();
  65. virtual void setNumTasks(int numTasks);
  66. virtual int getNumTasks() const
  67. {
  68. return 1;
  69. }
  70. virtual btBarrier* createBarrier();
  71. virtual btCriticalSection* createCriticalSection();
  72. virtual void deleteBarrier(btBarrier* barrier);
  73. virtual void deleteCriticalSection(btCriticalSection* criticalSection);
  74. };
  75. #endif //BT_SEQUENTIAL_THREAD_SUPPORT_H