Bullet Collision Detection & Physics Library: btThreads.h Source File

Bullet Collision Detection & Physics Library

btThreads.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2003-2014 Erwin Coumans http://bullet.googlecode.com
3
4 This software is provided 'as-is', without any express or implied warranty.
5 In no event will the authors be held liable for any damages arising from the use of this software.
6 Permission is granted to anyone to use this software for any purpose,
7 including commercial applications, and to alter it and redistribute it freely,
8 subject to the following restrictions:
9
10 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.
11 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
12 3. This notice may not be removed or altered from any source distribution.
13 */
14
15
16
17 #ifndef BT_THREADS_H
18 #define BT_THREADS_H
19
20 #include "btScalar.h" // has definitions like SIMD_FORCE_INLINE
21
28 class btSpinMutex
29 {
30 int mLock;
31
32 public:
33 btSpinMutex()
34 {
35 mLock = 0;
36 }
37 void lock();
38 void unlock();
39 bool tryLock();
40 };
41
42 #if BT_THREADSAFE
43
44 // for internal Bullet use only
45 SIMD_FORCE_INLINE void btMutexLock( btSpinMutex* mutex )
46 {
47 mutex->lock();
48 }
49
50 SIMD_FORCE_INLINE void btMutexUnlock( btSpinMutex* mutex )
51 {
52 mutex->unlock();
53 }
54
55 SIMD_FORCE_INLINE bool btMutexTryLock( btSpinMutex* mutex )
56 {
57 return mutex->tryLock();
58 }
59
60 // for internal use only
61 bool btIsMainThread();
62 unsigned int btGetCurrentThreadIndex();
63 const unsigned int BT_MAX_THREAD_COUNT = 64;
64
65 #else
66
67 // for internal Bullet use only
68 // if BT_THREADSAFE is undefined or 0, should optimize away to nothing
69 SIMD_FORCE_INLINE void btMutexLock( btSpinMutex* ) {}
70 SIMD_FORCE_INLINE void btMutexUnlock( btSpinMutex* ) {}
71 SIMD_FORCE_INLINE bool btMutexTryLock( btSpinMutex* ) {return true;}
72 #endif
73
74
75 #endif //BT_THREADS_H
btMutexLock
void btMutexLock(btSpinMutex *)
Definition: btThreads.h:69
btSpinMutex::tryLock
bool tryLock()
Definition: btThreads.cpp:223
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:64
btSpinMutex
btSpinMutex – lightweight spin-mutex implemented with atomic ops, never puts a thread to sleep beca...
Definition: btThreads.h:28
btSpinMutex::btSpinMutex
btSpinMutex()
Definition: btThreads.h:33
btMutexTryLock
bool btMutexTryLock(btSpinMutex *)
Definition: btThreads.h:71
btSpinMutex::lock
void lock()
Definition: btThreads.cpp:213
btSpinMutex::mLock
int mLock
Definition: btThreads.h:30
btSpinMutex::unlock
void unlock()
Definition: btThreads.cpp:218
btMutexUnlock
void btMutexUnlock(btSpinMutex *)
Definition: btThreads.h:70
btScalar.h