2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
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:
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.
16
#include "LinearMath/btScalar.h"
17
#include "PlatformDefinitions.h"
19
#ifdef USE_WIN32_THREADING //platform specific defines are defined in PlatformDefinitions.h
21
#ifndef BT_WIN32_THREAD_SUPPORT_H
22
#define BT_WIN32_THREAD_SUPPORT_H
24
#include "LinearMath/btAlignedObjectArray.h"
26
#include "btThreadSupportInterface.h"
29
typedef void (*Win32ThreadFunc)(void* userPtr,void* lsMemory);
30
typedef void* (*Win32lsMemorySetupFunc)();
33
///Win32ThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication
34
class Win32ThreadSupport : public btThreadSupportInterface
37
///placeholder, until libspe2 support is there
44
Win32ThreadFunc m_userThreadFunc;
45
void* m_userPtr; //for taskDesc etc
46
void* m_lsMemory; //initialized using Win32LocalStoreMemorySetupFunc
48
void* m_threadHandle; //this one is calling 'Win32ThreadFunc'
50
void* m_eventStartHandle;
51
char m_eventStartHandleName[32];
53
void* m_eventCompletetHandle;
54
char m_eventCompletetHandleName[32];
60
btAlignedObjectArray<btSpuStatus> m_activeSpuStatus;
61
btAlignedObjectArray<void*> m_completeHandles;
65
///Setup and initialize SPU/CELL/Libspe2
67
struct Win32ThreadConstructionInfo
69
Win32ThreadConstructionInfo(char* uniqueName,
70
Win32ThreadFunc userThreadFunc,
71
Win32lsMemorySetupFunc lsMemoryFunc,
73
int threadStackSize=65535
75
:m_uniqueName(uniqueName),
76
m_userThreadFunc(userThreadFunc),
77
m_lsMemoryFunc(lsMemoryFunc),
78
m_numThreads(numThreads),
79
m_threadStackSize(threadStackSize)
85
Win32ThreadFunc m_userThreadFunc;
86
Win32lsMemorySetupFunc m_lsMemoryFunc;
88
int m_threadStackSize;
94
Win32ThreadSupport(const Win32ThreadConstructionInfo& threadConstructionInfo);
96
///cleanup/shutdown Libspe2
97
virtual ~Win32ThreadSupport();
99
void startThreads(const Win32ThreadConstructionInfo& threadInfo);
102
///send messages to SPUs
103
virtual void sendRequest(uint32_t uiCommand, ppu_address_t uiArgument0, uint32_t uiArgument1);
105
///check for messages from SPUs
106
virtual void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1);
108
virtual bool isTaskCompleted(unsigned int *puiArgument0, unsigned int *puiArgument1, int timeOutInMilliseconds);
110
///start the spus (can be called at the beginning of each frame, to make sure that the right SPU program is loaded)
111
virtual void startSPU();
113
///tell the task scheduler we are done with the SPU tasks
114
virtual void stopSPU();
116
virtual void setNumTasks(int numTasks)
118
m_maxNumTasks = numTasks;
121
virtual int getNumTasks() const
123
return m_maxNumTasks;
126
virtual void* getThreadLocalMemory(int taskId)
128
return m_activeSpuStatus[taskId].m_lsMemory;
130
virtual btBarrier* createBarrier();
132
virtual btCriticalSection* createCriticalSection();
136
#endif //BT_WIN32_THREAD_SUPPORT_H
138
#endif //USE_WIN32_THREADING