Panda3D
Loading...
Searching...
No Matches
atomicAdjustDummyImpl.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 atomicAdjustDummyImpl.I
10 * @author drose
11 * @date 2002-08-09
12 */
13
14/**
15 * Atomically increments the indicated variable.
16 */
17ALWAYS_INLINE void AtomicAdjustDummyImpl::
18inc(TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
19 ++var;
20}
21
22/**
23 * Atomically decrements the indicated variable and returns true if the new
24 * value is nonzero, false if it is zero.
25 */
26ALWAYS_INLINE bool AtomicAdjustDummyImpl::
27dec(TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
28 return (--var) != 0;
29}
30
31/**
32 * Atomically computes var += delta. It is legal for delta to be negative.
33 * Returns the result of the addition.
34 */
35ALWAYS_INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
36add(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Integer delta) {
37 Integer new_value = var + delta;
38 var = new_value;
39 return new_value;
40}
41
42/**
43 * Atomically changes the indicated variable and returns the original value.
44 */
45ALWAYS_INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
46set(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Integer new_value) {
47 Integer orig_value = var;
48 var = new_value;
49 return orig_value;
50}
51
52/**
53 * Atomically retrieves the snapshot value of the indicated variable. This is
54 * the only guaranteed safe way to retrieve the value that other threads might
55 * be asynchronously setting, incrementing, or decrementing (via other
56 * AtomicAjust methods).
57 */
58ALWAYS_INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
59get(const TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
60 return var;
61}
62
63/**
64 * Atomically changes the indicated variable and returns the original value.
65 */
66ALWAYS_INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl::
67set_ptr(TVOLATILE AtomicAdjustDummyImpl::Pointer &var,
68 AtomicAdjustDummyImpl::Pointer new_value) {
69 Pointer orig_value = var;
70 var = new_value;
71 return orig_value;
72}
73
74/**
75 * Atomically retrieves the snapshot value of the indicated variable. This is
76 * the only guaranteed safe way to retrieve the value that other threads might
77 * be asynchronously setting, incrementing, or decrementing (via other
78 * AtomicAjust methods).
79 */
80ALWAYS_INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl::
81get_ptr(const TVOLATILE AtomicAdjustDummyImpl::Pointer &var) {
82 return var;
83}
84
85/**
86 * Atomic compare and exchange.
87 *
88 * If mem is equal to old_value, store new_value in mem. In either case,
89 * return the original value of mem. The caller can test for success by
90 * comparing return_value == old_value.
91 */
92ALWAYS_INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
93compare_and_exchange(TVOLATILE AtomicAdjustDummyImpl::Integer &mem,
94 AtomicAdjustDummyImpl::Integer old_value,
95 AtomicAdjustDummyImpl::Integer new_value) {
96 Integer orig_value = mem;
97 if (mem == old_value) {
98 mem = new_value;
99 }
100 return orig_value;
101}
102
103/**
104 * Atomic compare and exchange.
105 *
106 * As above, but works on pointers instead of integers.
107 */
108ALWAYS_INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl::
109compare_and_exchange_ptr(TVOLATILE AtomicAdjustDummyImpl::Pointer &mem,
110 AtomicAdjustDummyImpl::Pointer old_value,
111 AtomicAdjustDummyImpl::Pointer new_value) {
112 Pointer orig_value = mem;
113 if (mem == old_value) {
114 mem = new_value;
115 }
116 return orig_value;
117}
static Integer set(Integer &var, Integer new_value)
Atomically changes the indicated variable and returns the original value.
static Integer add(Integer &var, Integer delta)
Atomically computes var += delta.
static bool dec(Integer &var)
Atomically decrements the indicated variable and returns true if the new value is nonzero,...
static Integer compare_and_exchange(Integer &mem, Integer old_value, Integer new_value)
Atomic compare and exchange.
static Pointer set_ptr(Pointer &var, Pointer 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 void inc(Integer &var)
Atomically increments the indicated variable.
static Pointer get_ptr(const Pointer &var)
Atomically retrieves the snapshot value of the indicated variable.
static Integer get(const Integer &var)
Atomically retrieves the snapshot value of the indicated variable.