Panda3D
atomicAdjustDummyImpl.I
1 // Filename: atomicAdjustDummyImpl.I
2 // Created by: drose (09Aug02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: AtomicAdjustDummyImpl::inc
18 // Access: Public, Static
19 // Description: Atomically increments the indicated variable.
20 ////////////////////////////////////////////////////////////////////
21 INLINE void AtomicAdjustDummyImpl::
22 inc(TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
23  ++var;
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: AtomicAdjustDummyImpl::dec
28 // Access: Public, Static
29 // Description: Atomically decrements the indicated variable and
30 // returns true if the new value is nonzero, false if it
31 // is zero.
32 ////////////////////////////////////////////////////////////////////
33 INLINE bool AtomicAdjustDummyImpl::
34 dec(TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
35  return (--var) != 0;
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: AtomicAdjustDummyImpl::add
40 // Access: Public, Static
41 // Description: Atomically computes var += delta. It is legal for
42 // delta to be negative.
43 ////////////////////////////////////////////////////////////////////
44 INLINE void AtomicAdjustDummyImpl::
45 add(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Integer delta) {
46  var += delta;
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: AtomicAdjustDummyImpl::set
51 // Access: Public, Static
52 // Description: Atomically changes the indicated variable and
53 // returns the original value.
54 ////////////////////////////////////////////////////////////////////
55 INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
56 set(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Integer new_value) {
57  Integer orig_value = var;
58  var = new_value;
59  return orig_value;
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: AtomicAdjustDummyImpl::get
64 // Access: Public, Static
65 // Description: Atomically retrieves the snapshot value of the
66 // indicated variable. This is the only guaranteed safe
67 // way to retrieve the value that other threads might be
68 // asynchronously setting, incrementing, or decrementing
69 // (via other AtomicAjust methods).
70 ////////////////////////////////////////////////////////////////////
71 INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
72 get(const TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
73  return var;
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: AtomicAdjustDummyImpl::set_ptr
78 // Access: Public, Static
79 // Description: Atomically changes the indicated variable and
80 // returns the original value.
81 ////////////////////////////////////////////////////////////////////
82 INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl::
83 set_ptr(TVOLATILE AtomicAdjustDummyImpl::Pointer &var,
84  AtomicAdjustDummyImpl::Pointer new_value) {
85  Pointer orig_value = var;
86  var = new_value;
87  return orig_value;
88 }
89 
90 ////////////////////////////////////////////////////////////////////
91 // Function: AtomicAdjustDummyImpl::get_ptr
92 // Access: Public, Static
93 // Description: Atomically retrieves the snapshot value of the
94 // indicated variable. This is the only guaranteed safe
95 // way to retrieve the value that other threads might be
96 // asynchronously setting, incrementing, or decrementing
97 // (via other AtomicAjust methods).
98 ////////////////////////////////////////////////////////////////////
99 INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl::
100 get_ptr(const TVOLATILE AtomicAdjustDummyImpl::Pointer &var) {
101  return var;
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: AtomicAdjustDummyImpl::compare_and_exchange
106 // Access: Public, Static
107 // Description: Atomic compare and exchange.
108 //
109 // If mem is equal to old_value, store new_value in mem.
110 // In either case, return the original value of mem.
111 // The caller can test for success by comparing
112 // return_value == old_value.
113 ////////////////////////////////////////////////////////////////////
114 INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
115 compare_and_exchange(TVOLATILE AtomicAdjustDummyImpl::Integer &mem,
116  AtomicAdjustDummyImpl::Integer old_value,
117  AtomicAdjustDummyImpl::Integer new_value) {
118  Integer orig_value = mem;
119  if (mem == old_value) {
120  mem = new_value;
121  }
122  return orig_value;
123 }
124 
125 ////////////////////////////////////////////////////////////////////
126 // Function: AtomicAdjustDummyImpl::compare_and_exchange_ptr
127 // Access: Public, Static
128 // Description: Atomic compare and exchange.
129 //
130 // As above, but works on pointers instead of integers.
131 ////////////////////////////////////////////////////////////////////
132 INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl::
133 compare_and_exchange_ptr(TVOLATILE AtomicAdjustDummyImpl::Pointer &mem,
134  AtomicAdjustDummyImpl::Pointer old_value,
135  AtomicAdjustDummyImpl::Pointer new_value) {
136  Pointer orig_value = mem;
137  if (mem == old_value) {
138  mem = new_value;
139  }
140  return orig_value;
141 }
static Pointer get_ptr(const Pointer &var)
Atomically retrieves the snapshot value of the indicated variable.
static void add(Integer &var, Integer delta)
Atomically computes var += delta.
static void inc(Integer &var)
Atomically increments the indicated variable.
static bool dec(Integer &var)
Atomically decrements the indicated variable and returns true if the new value is nonzero...
static Integer get(const Integer &var)
Atomically retrieves the snapshot value of the indicated variable.
static Pointer set_ptr(Pointer &var, Pointer new_value)
Atomically changes the indicated variable and returns the original value.
static Integer set(Integer &var, Integer new_value)
Atomically changes the indicated variable and returns the original value.
static Pointer compare_and_exchange_ptr(Pointer &mem, Pointer old_value, Pointer new_value)
Atomic compare and exchange.
static Integer compare_and_exchange(Integer &mem, Integer old_value, Integer new_value)
Atomic compare and exchange.