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 | |
---|
17 | #include "LinearMath/btScalar.h" |
---|
18 | #include "PlatformDefinitions.h" |
---|
19 | |
---|
20 | #ifdef USE_PTHREADS //platform specific defines are defined in PlatformDefinitions.h |
---|
21 | #include <pthread.h> |
---|
22 | #include <semaphore.h> |
---|
23 | |
---|
24 | #ifndef POSIX_THREAD_SUPPORT_H |
---|
25 | #define POSIX_THREAD_SUPPORT_H |
---|
26 | |
---|
27 | #include "LinearMath/btAlignedObjectArray.h" |
---|
28 | |
---|
29 | #include "btThreadSupportInterface.h" |
---|
30 | |
---|
31 | |
---|
32 | typedef void (*PosixThreadFunc)(void* userPtr,void* lsMemory); |
---|
33 | typedef void* (*PosixlsMemorySetupFunc)(); |
---|
34 | |
---|
35 | // PosixThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication |
---|
36 | class PosixThreadSupport : public btThreadSupportInterface |
---|
37 | { |
---|
38 | public: |
---|
39 | typedef enum sStatus { |
---|
40 | STATUS_BUSY, |
---|
41 | STATUS_READY, |
---|
42 | STATUS_FINISHED |
---|
43 | } Status; |
---|
44 | |
---|
45 | // placeholder, until libspe2 support is there |
---|
46 | struct btSpuStatus |
---|
47 | { |
---|
48 | uint32_t m_taskId; |
---|
49 | uint32_t m_commandId; |
---|
50 | uint32_t m_status; |
---|
51 | |
---|
52 | PosixThreadFunc m_userThreadFunc; |
---|
53 | void* m_userPtr; //for taskDesc etc |
---|
54 | void* m_lsMemory; //initialized using PosixLocalStoreMemorySetupFunc |
---|
55 | |
---|
56 | pthread_t thread; |
---|
57 | sem_t startSemaphore; |
---|
58 | |
---|
59 | unsigned long threadUsed; |
---|
60 | }; |
---|
61 | private: |
---|
62 | |
---|
63 | btAlignedObjectArray<btSpuStatus> m_activeSpuStatus; |
---|
64 | public: |
---|
65 | ///Setup and initialize SPU/CELL/Libspe2 |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | struct ThreadConstructionInfo |
---|
70 | { |
---|
71 | ThreadConstructionInfo(char* uniqueName, |
---|
72 | PosixThreadFunc userThreadFunc, |
---|
73 | PosixlsMemorySetupFunc lsMemoryFunc, |
---|
74 | int numThreads=1, |
---|
75 | int threadStackSize=65535 |
---|
76 | ) |
---|
77 | :m_uniqueName(uniqueName), |
---|
78 | m_userThreadFunc(userThreadFunc), |
---|
79 | m_lsMemoryFunc(lsMemoryFunc), |
---|
80 | m_numThreads(numThreads), |
---|
81 | m_threadStackSize(threadStackSize) |
---|
82 | { |
---|
83 | |
---|
84 | } |
---|
85 | |
---|
86 | char* m_uniqueName; |
---|
87 | PosixThreadFunc m_userThreadFunc; |
---|
88 | PosixlsMemorySetupFunc m_lsMemoryFunc; |
---|
89 | int m_numThreads; |
---|
90 | int m_threadStackSize; |
---|
91 | |
---|
92 | }; |
---|
93 | |
---|
94 | PosixThreadSupport(ThreadConstructionInfo& threadConstructionInfo); |
---|
95 | |
---|
96 | ///cleanup/shutdown Libspe2 |
---|
97 | virtual ~PosixThreadSupport(); |
---|
98 | |
---|
99 | void startThreads(ThreadConstructionInfo& threadInfo); |
---|
100 | |
---|
101 | |
---|
102 | ///send messages to SPUs |
---|
103 | virtual void sendRequest(uint32_t uiCommand, uint32_t uiArgument0, uint32_t uiArgument1); |
---|
104 | |
---|
105 | ///check for messages from SPUs |
---|
106 | virtual void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1); |
---|
107 | |
---|
108 | ///start the spus (can be called at the beginning of each frame, to make sure that the right SPU program is loaded) |
---|
109 | virtual void startSPU(); |
---|
110 | |
---|
111 | ///tell the task scheduler we are done with the SPU tasks |
---|
112 | virtual void stopSPU(); |
---|
113 | |
---|
114 | virtual void setNumTasks(int numTasks) |
---|
115 | { |
---|
116 | } |
---|
117 | |
---|
118 | }; |
---|
119 | |
---|
120 | #endif // POSIX_THREAD_SUPPORT_H |
---|
121 | |
---|
122 | #endif // USE_PTHREADS |
---|