Panda3D
conditionVarSpinlockImpl.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 conditionVarSpinlockImpl.cxx
10  * @author drose
11  * @date 2006-04-11
12  */
13 
14 #include "selectThreadImpl.h"
15 
16 #ifdef MUTEX_SPINLOCK
17 
19 #include "trueClock.h"
20 
21 #if defined(__i386__) || defined(__x86_64) || defined(_M_IX86) || defined(_M_X64)
22 #include <emmintrin.h>
23 #define PAUSE() _mm_pause()
24 #else
25 #define PAUSE()
26 #endif
27 
28 /**
29  *
30  */
31 void ConditionVarSpinlockImpl::
32 wait() {
33  AtomicAdjust::Integer current = _event;
34  _mutex.unlock();
35 
36  while (AtomicAdjust::get(_event) == current) {
37  PAUSE();
38  }
39 
40  _mutex.lock();
41 }
42 
43 /**
44  *
45  */
46 void ConditionVarSpinlockImpl::
47 wait(double timeout) {
49  double end_time = clock->get_short_time() + timeout;
50 
51  AtomicAdjust::Integer current = _event;
52  _mutex.unlock();
53 
54  while (AtomicAdjust::get(_event) == current && clock->get_short_time() < end_time) {
55  PAUSE();
56  }
57 
58  _mutex.lock();
59 }
60 
61 #undef PAUSE
62 
63 #endif // MUTEX_SPINLOCK
static TrueClock * get_global_ptr()
Returns a pointer to the one TrueClock object in the world.
Definition: trueClock.I:68
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static Integer get(const Integer &var)
Atomically retrieves the snapshot value of the indicated variable.
An interface to whatever real-time clock we might have available in the current environment.
Definition: trueClock.h:33