Panda3D
mutexSpinlockImpl.cxx
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.cxx
10  * @author drose
11  * @date 2006-04-11
12  */
13 
14 #include "selectThreadImpl.h"
15 
16 #ifdef MUTEX_SPINLOCK
17 
18 #include "mutexSpinlockImpl.h"
19 
20 #if defined(__i386__) || defined(__x86_64) || defined(_M_IX86) || defined(_M_X64)
21 #include <emmintrin.h>
22 #define PAUSE() _mm_pause()
23 #else
24 #define PAUSE()
25 #endif
26 
27 /**
28  *
29  */
30 void MutexSpinlockImpl::
31 do_lock() {
32  // Loop until we changed the flag from 0 to 1 (and it wasn't already 1).
33  while (_flag.test_and_set(std::memory_order_acquire)) {
34  PAUSE();
35  }
36 }
37 
38 #endif // MUTEX_SPINLOCK
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.