Panda3D
conditionVarSpinlockImpl.h
1 // Filename: conditionVarSpinlockImpl.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 CONDITIONVARSPINLOCKIMPL_H
16 #define CONDITIONVARSPINLOCKIMPL_H
17 
18 #include "pandabase.h"
19 #include "selectThreadImpl.h"
20 
21 #ifdef MUTEX_SPINLOCK
22 
23 #include "mutexSpinlockImpl.h"
24 #include "pnotify.h"
25 #include "atomicAdjust.h"
26 
27 class MutexSpinlockImpl;
28 
29 ////////////////////////////////////////////////////////////////////
30 // Class : ConditionVarSpinlockImpl
31 // Description : Uses a simple user-space spinlock to implement a
32 // condition variable. It is usually not a good idea to
33 // use this implementation, unless you are building
34 // Panda for a specific application on a specific SMP
35 // machine, and you are confident that you have at least
36 // as many CPU's as you have threads.
37 ////////////////////////////////////////////////////////////////////
38 class EXPCL_PANDA_PIPELINE ConditionVarSpinlockImpl {
39 public:
40  INLINE ConditionVarSpinlockImpl(MutexSpinlockImpl &mutex);
41  INLINE ~ConditionVarSpinlockImpl();
42 
43  void wait();
44  INLINE void notify();
45  INLINE void notify_all();
46 
47 private:
48  MutexSpinlockImpl &_mutex;
49  TVOLATILE AtomicAdjust::Integer _event;
50 };
51 
52 #include "conditionVarSpinlockImpl.I"
53 
54 #endif // MUTEX_SPINLOCK
55 
56 #endif