Panda3D
|
00001 // Filename: mutexSpinlockImpl.h 00002 // Created by: drose (11Apr06) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef MUTEXSPINLOCKIMPL_H 00016 #define MUTEXSPINLOCKIMPL_H 00017 00018 #include "dtoolbase.h" 00019 #include "selectThreadImpl.h" 00020 00021 #ifdef MUTEX_SPINLOCK 00022 00023 #include "atomicAdjust.h" 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Class : MutexSpinlockImpl 00027 // Description : Uses a simple user-space spinlock to implement a 00028 // mutex. It is usually not a good idea to use this 00029 // implementation, unless you are building Panda for a 00030 // specific application on a specific SMP machine, and 00031 // you are confident that you have at least as many 00032 // CPU's as you have threads. 00033 //////////////////////////////////////////////////////////////////// 00034 class EXPCL_DTOOL MutexSpinlockImpl { 00035 public: 00036 INLINE MutexSpinlockImpl(); 00037 INLINE ~MutexSpinlockImpl(); 00038 00039 INLINE void acquire(); 00040 INLINE bool try_acquire(); 00041 INLINE void release(); 00042 00043 private: 00044 void do_lock(); 00045 00046 TVOLATILE AtomicAdjust::Integer _lock; 00047 }; 00048 00049 #include "mutexSpinlockImpl.I" 00050 00051 #endif // MUTEX_SPINLOCK 00052 00053 #endif