Panda3D
mutexSpinlockImpl.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file mutexSpinlockImpl.I
10  * @author drose
11  * @date 2006-04-11
12  */
13 
14 /**
15  *
16  */
17 INLINE void MutexSpinlockImpl::
18 lock() {
19  if (!try_lock()) {
20  do_lock();
21  }
22 }
23 
24 /**
25  *
26  */
27 INLINE bool MutexSpinlockImpl::
28 try_lock() {
29  return !_flag.test_and_set(std::memory_order_acquire);
30 }
31 
32 /**
33  *
34  */
35 INLINE void MutexSpinlockImpl::
36 unlock() {
37  _flag.clear(std::memory_order_release);
38 }