Panda3D
|
00001 // Filename: mutexSpinlockImpl.I 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 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: MutexSpinlockImpl::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE MutexSpinlockImpl:: 00022 MutexSpinlockImpl() { 00023 _lock = 0; 00024 } 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: MutexSpinlockImpl::Destructor 00028 // Access: Public 00029 // Description: 00030 //////////////////////////////////////////////////////////////////// 00031 INLINE MutexSpinlockImpl:: 00032 ~MutexSpinlockImpl() { 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function: MutexSpinlockImpl::acquire 00037 // Access: Public 00038 // Description: 00039 //////////////////////////////////////////////////////////////////// 00040 INLINE void MutexSpinlockImpl:: 00041 acquire() { 00042 if (!try_acquire()) { 00043 do_lock(); 00044 } 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: MutexSpinlockImpl::try_acquire 00049 // Access: Public 00050 // Description: 00051 //////////////////////////////////////////////////////////////////// 00052 INLINE bool MutexSpinlockImpl:: 00053 try_acquire() { 00054 return (AtomicAdjust::compare_and_exchange(_lock, 0, 1) == 0); 00055 } 00056 00057 //////////////////////////////////////////////////////////////////// 00058 // Function: MutexSpinlockImpl::release 00059 // Access: Public 00060 // Description: 00061 //////////////////////////////////////////////////////////////////// 00062 INLINE void MutexSpinlockImpl:: 00063 release() { 00064 AtomicAdjust::set(_lock, 0); 00065 }