Merge pull request #1874 from John3/readmeUpdate
[Torque-3d.git] / Engine / lib / bullet / src / BulletMultiThreaded / SpuSync.h
blob4157b8f0d1187e77d746a4142a2fd6c82267b78c
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2007 Starbreeze Studios
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.
15 Written by: Marten Svanfeldt
18 #ifndef BT_SPU_SYNC_H
19 #define BT_SPU_SYNC_H
22 #include "PlatformDefinitions.h"
25 #if defined(WIN32)
27 #define WIN32_LEAN_AND_MEAN
28 #ifdef _XBOX
29 #include <Xtl.h>
30 #else
31 #include <Windows.h>
32 #endif
34 ///The btSpinlock is a structure to allow multi-platform synchronization. This allows to port the SPU tasks to other platforms.
35 class btSpinlock
37 public:
38 //typedef volatile LONG SpinVariable;
39 typedef CRITICAL_SECTION SpinVariable;
41 btSpinlock (SpinVariable* var)
42 : spinVariable (var)
45 void Init ()
47 //*spinVariable = 0;
48 InitializeCriticalSection(spinVariable);
51 void Lock ()
53 EnterCriticalSection(spinVariable);
56 void Unlock ()
58 LeaveCriticalSection(spinVariable);
61 private:
62 SpinVariable* spinVariable;
66 #elif defined (__CELLOS_LV2__)
68 //#include <cell/atomic.h>
69 #include <cell/sync/mutex.h>
71 ///The btSpinlock is a structure to allow multi-platform synchronization. This allows to port the SPU tasks to other platforms.
72 class btSpinlock
74 public:
75 typedef CellSyncMutex SpinVariable;
77 btSpinlock (SpinVariable* var)
78 : spinVariable (var)
81 void Init ()
83 #ifndef __SPU__
84 //*spinVariable = 1;
85 cellSyncMutexInitialize(spinVariable);
86 #endif
91 void Lock ()
93 #ifdef __SPU__
94 // lock semaphore
95 /*while (cellAtomicTestAndDecr32(atomic_buf, (uint64_t)spinVariable) == 0)
98 };*/
99 cellSyncMutexLock((uint64_t)spinVariable);
100 #endif
103 void Unlock ()
105 #ifdef __SPU__
106 //cellAtomicIncr32(atomic_buf, (uint64_t)spinVariable);
107 cellSyncMutexUnlock((uint64_t)spinVariable);
108 #endif
112 private:
113 SpinVariable* spinVariable;
114 ATTRIBUTE_ALIGNED128(uint32_t atomic_buf[32]);
117 #else
118 //create a dummy implementation (without any locking) useful for serial processing
119 class btSpinlock
121 public:
122 typedef int SpinVariable;
124 btSpinlock (SpinVariable* var)
125 : spinVariable (var)
128 void Init ()
132 void Lock ()
136 void Unlock ()
140 private:
141 SpinVariable* spinVariable;
145 #endif
148 #endif //BT_SPU_SYNC_H