Bullet Collision Detection & Physics Library
Win32ThreadSupport.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #include "LinearMath/btScalar.h"
17 #include "PlatformDefinitions.h"
18 
19 #ifdef USE_WIN32_THREADING //platform specific defines are defined in PlatformDefinitions.h
20 
21 #ifndef BT_WIN32_THREAD_SUPPORT_H
22 #define BT_WIN32_THREAD_SUPPORT_H
23 
25 
27 
28 
29 typedef void (*Win32ThreadFunc)(void* userPtr,void* lsMemory);
30 typedef void* (*Win32lsMemorySetupFunc)();
31 
32 
35 {
36 public:
38  struct btSpuStatus
39  {
43 
45  void* m_userPtr; //for taskDesc etc
46  void* m_lsMemory; //initialized using Win32LocalStoreMemorySetupFunc
47 
48  void* m_threadHandle; //this one is calling 'Win32ThreadFunc'
49 
52 
55 
56 
57  };
58 private:
59 
62 
64 public:
66 
68  {
69  Win32ThreadConstructionInfo(const char* uniqueName,
70  Win32ThreadFunc userThreadFunc,
71  Win32lsMemorySetupFunc lsMemoryFunc,
72  int numThreads=1,
73  int threadStackSize=65535
74  )
75  :m_uniqueName(uniqueName),
76  m_userThreadFunc(userThreadFunc),
77  m_lsMemoryFunc(lsMemoryFunc),
78  m_numThreads(numThreads),
79  m_threadStackSize(threadStackSize)
80  {
81 
82  }
83 
84  const char* m_uniqueName;
89 
90  };
91 
92 
93 
94  Win32ThreadSupport(const Win32ThreadConstructionInfo& threadConstructionInfo);
95 
97  virtual ~Win32ThreadSupport();
98 
99  void startThreads(const Win32ThreadConstructionInfo& threadInfo);
100 
101 
103  virtual void sendRequest(uint32_t uiCommand, ppu_address_t uiArgument0, uint32_t uiArgument1);
104 
106  virtual void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1);
107 
108  virtual bool isTaskCompleted(unsigned int *puiArgument0, unsigned int *puiArgument1, int timeOutInMilliseconds);
109 
111  virtual void startSPU();
112 
114  virtual void stopSPU();
115 
116  virtual void setNumTasks(int numTasks)
117  {
118  m_maxNumTasks = numTasks;
119  }
120 
121  virtual int getNumTasks() const
122  {
123  return m_maxNumTasks;
124  }
125 
126  virtual void* getThreadLocalMemory(int taskId)
127  {
128  return m_activeSpuStatus[taskId].m_lsMemory;
129  }
130  virtual btBarrier* createBarrier();
131 
133 
134  virtual void deleteBarrier(btBarrier* barrier);
135 
136  virtual void deleteCriticalSection(btCriticalSection* criticalSection);
137 };
138 
139 #endif //BT_WIN32_THREAD_SUPPORT_H
140 
141 #endif //USE_WIN32_THREADING
virtual void startSPU()
start the spus (can be called at the beginning of each frame, to make sure that the right SPU program...
virtual btCriticalSection * createCriticalSection()
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
uint32_t ppu_address_t
void *(* Win32lsMemorySetupFunc)()
virtual bool isTaskCompleted(unsigned int *puiArgument0, unsigned int *puiArgument1, int timeOutInMilliseconds)
check for messages from SPUs
void startThreads(const Win32ThreadConstructionInfo &threadInfo)
Win32ThreadSupport(const Win32ThreadConstructionInfo &threadConstructionInfo)
The number of threads should be equal to the number of available cores.
virtual void stopSPU()
tell the task scheduler we are done with the SPU tasks
virtual void deleteBarrier(btBarrier *barrier)
Win32ThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication...
placeholder, until libspe2 support is there
virtual void * getThreadLocalMemory(int taskId)
Setup and initialize SPU/CELL/Libspe2.
unsigned int uint32_t
virtual void setNumTasks(int numTasks)
tell the task scheduler to use no more than numTasks tasks
virtual void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1)
check for messages from SPUs
btAlignedObjectArray< btSpuStatus > m_activeSpuStatus
virtual ~Win32ThreadSupport()
cleanup/shutdown Libspe2
virtual btBarrier * createBarrier()
btAlignedObjectArray< void * > m_completeHandles
void(* Win32ThreadFunc)(void *userPtr, void *lsMemory)
Win32ThreadConstructionInfo(const char *uniqueName, Win32ThreadFunc userThreadFunc, Win32lsMemorySetupFunc lsMemoryFunc, int numThreads=1, int threadStackSize=65535)
static void barrier(unsigned int a)
virtual void sendRequest(uint32_t uiCommand, ppu_address_t uiArgument0, uint32_t uiArgument1)
send messages to SPUs
virtual int getNumTasks() const
virtual void deleteCriticalSection(btCriticalSection *criticalSection)