Panda3D
 All Classes Functions Variables Enumerations
mutexSpinlockImpl.h
1 // Filename: mutexSpinlockImpl.h
2 // Created by: drose (11Apr06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef MUTEXSPINLOCKIMPL_H
16 #define MUTEXSPINLOCKIMPL_H
17 
18 #include "dtoolbase.h"
19 #include "selectThreadImpl.h"
20 
21 #ifdef MUTEX_SPINLOCK
22 
23 #include "atomicAdjust.h"
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : MutexSpinlockImpl
27 // Description : Uses a simple user-space spinlock to implement a
28 // mutex. It is usually not a good idea to use this
29 // implementation, unless you are building Panda for a
30 // specific application on a specific SMP machine, and
31 // you are confident that you have at least as many
32 // CPU's as you have threads.
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_DTOOL MutexSpinlockImpl {
35 public:
36  INLINE MutexSpinlockImpl();
37  INLINE ~MutexSpinlockImpl();
38 
39  INLINE void acquire();
40  INLINE bool try_acquire();
41  INLINE void release();
42 
43 private:
44  void do_lock();
45 
46  TVOLATILE AtomicAdjust::Integer _lock;
47 };
48 
49 #include "mutexSpinlockImpl.I"
50 
51 #endif // MUTEX_SPINLOCK
52 
53 #endif