Panda3D

Loading...
Searching...
No Matches
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
18#include "conditionVarSpinlockImpl.h"
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::
32wait() {
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::
47wait(double timeout) {
48 TrueClock *clock = TrueClock::get_global_ptr();
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
AtomicAdjustDummyImpl::get
static Integer get(const Integer &var)
Atomically retrieves the snapshot value of the indicated variable.
Definition atomicAdjustDummyImpl.I:59
TrueClock
An interface to whatever real-time clock we might have available in the current environment.
Definition trueClock.h:33
TrueClock::get_global_ptr
static TrueClock * get_global_ptr()
Returns a pointer to the one TrueClock object in the world.
Definition trueClock.I:68
conditionVarSpinlockImpl.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
selectThreadImpl.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
trueClock.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.