Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/bullet/BulletMultiThreaded/SpuSync.h @ 1967

Last change on this file since 1967 was 1966, checked in by rgrieder, 16 years ago

Let's go for multithreaded physics!

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2007 Starbreeze Studios
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14
15Written by: Marten Svanfeldt
16*/
17
18#ifndef SPU_SYNC_H
19#define SPU_SYNC_H
20
21
22#include "PlatformDefinitions.h"
23
24
25#if defined(WIN32)
26
27#define WIN32_LEAN_AND_MEAN
28#ifdef _XBOX
29#include <Xtl.h>
30#else
31#include <Windows.h>
32#endif
33
34class btSpinlock
35{
36public:
37        //typedef volatile LONG SpinVariable;
38        typedef CRITICAL_SECTION SpinVariable;
39
40        btSpinlock (SpinVariable* var)
41                : spinVariable (var)
42        {}
43
44        void Init ()
45        {
46                //*spinVariable = 0;
47                InitializeCriticalSection(spinVariable);
48        }
49
50        void Lock ()
51        {
52                EnterCriticalSection(spinVariable);
53        }
54
55        void Unlock ()
56        {
57                LeaveCriticalSection(spinVariable);
58        }
59
60private:
61        SpinVariable* spinVariable;
62};
63
64
65#elif defined (__CELLOS_LV2__)
66
67//#include <cell/atomic.h>
68#include <cell/sync/mutex.h>
69
70class btSpinlock
71{
72public:
73        typedef CellSyncMutex SpinVariable;
74
75        btSpinlock (SpinVariable* var)
76                : spinVariable (var)
77        {}
78
79        void Init ()
80        {
81#ifndef __SPU__
82                //*spinVariable = 1;
83                cellSyncMutexInitialize(spinVariable);
84#endif
85        }
86
87
88
89        void Lock ()
90        {
91#ifdef __SPU__
92                // lock semaphore
93                /*while (cellAtomicTestAndDecr32(atomic_buf, (uint64_t)spinVariable) == 0)
94                {
95
96                };*/
97                cellSyncMutexLock((uint64_t)spinVariable);
98#endif
99        }
100
101        void Unlock ()
102        {
103#ifdef __SPU__
104                //cellAtomicIncr32(atomic_buf, (uint64_t)spinVariable);
105                cellSyncMutexUnlock((uint64_t)spinVariable);
106#endif
107        }
108
109
110private:
111        SpinVariable*   spinVariable;
112        ATTRIBUTE_ALIGNED128(uint32_t           atomic_buf[32]);
113};
114
115#else
116//create a dummy implementation (without any locking) useful for serial processing
117class btSpinlock
118{
119public:
120        typedef int  SpinVariable;
121
122        btSpinlock (SpinVariable* var)
123                : spinVariable (var)
124        {}
125
126        void Init ()
127        {
128        }
129
130        void Lock ()
131        {
132        }
133
134        void Unlock ()
135        {
136        }
137
138private:
139        SpinVariable* spinVariable;
140};
141
142
143#endif
144
145
146#endif
Note: See TracBrowser for help on using the repository browser.