Panda3D

atomicAdjustDummyImpl.I

00001 // Filename: atomicAdjustDummyImpl.I
00002 // Created by:  drose (09Aug02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: AtomicAdjustDummyImpl::inc
00018 //       Access: Public, Static
00019 //  Description: Atomically increments the indicated variable.
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE void AtomicAdjustDummyImpl::
00022 inc(TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
00023   ++var;
00024 }
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: AtomicAdjustDummyImpl::dec
00028 //       Access: Public, Static
00029 //  Description: Atomically decrements the indicated variable and
00030 //               returns true if the new value is nonzero, false if it
00031 //               is zero.
00032 ////////////////////////////////////////////////////////////////////
00033 INLINE bool AtomicAdjustDummyImpl::
00034 dec(TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
00035   return (--var) != 0;
00036 }
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //     Function: AtomicAdjustDummyImpl::add
00040 //       Access: Public, Static
00041 //  Description: Atomically computes var += delta.  It is legal for
00042 //               delta to be negative.
00043 ////////////////////////////////////////////////////////////////////
00044 INLINE void AtomicAdjustDummyImpl::
00045 add(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Integer delta) {
00046   var += delta;
00047 }
00048 
00049 ////////////////////////////////////////////////////////////////////
00050 //     Function: AtomicAdjustDummyImpl::set
00051 //       Access: Public, Static
00052 //  Description: Atomically changes the indicated variable and
00053 //               returns the original value.
00054 ////////////////////////////////////////////////////////////////////
00055 INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
00056 set(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Integer new_value) {
00057   Integer orig_value = var;
00058   var = new_value;
00059   return orig_value;
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //     Function: AtomicAdjustDummyImpl::get
00064 //       Access: Public, Static
00065 //  Description: Atomically retrieves the snapshot value of the
00066 //               indicated variable.  This is the only guaranteed safe
00067 //               way to retrieve the value that other threads might be
00068 //               asynchronously setting, incrementing, or decrementing
00069 //               (via other AtomicAjust methods).
00070 ////////////////////////////////////////////////////////////////////
00071 INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
00072 get(const TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
00073   return var;
00074 }
00075 
00076 ////////////////////////////////////////////////////////////////////
00077 //     Function: AtomicAdjustDummyImpl::set_ptr
00078 //       Access: Public, Static
00079 //  Description: Atomically changes the indicated variable and
00080 //               returns the original value.
00081 ////////////////////////////////////////////////////////////////////
00082 INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl::
00083 set_ptr(TVOLATILE AtomicAdjustDummyImpl::Pointer &var, 
00084         AtomicAdjustDummyImpl::Pointer new_value) {
00085   Pointer orig_value = var;
00086   var = new_value;
00087   return orig_value;
00088 }
00089 
00090 ////////////////////////////////////////////////////////////////////
00091 //     Function: AtomicAdjustDummyImpl::get_ptr
00092 //       Access: Public, Static
00093 //  Description: Atomically retrieves the snapshot value of the
00094 //               indicated variable.  This is the only guaranteed safe
00095 //               way to retrieve the value that other threads might be
00096 //               asynchronously setting, incrementing, or decrementing
00097 //               (via other AtomicAjust methods).
00098 ////////////////////////////////////////////////////////////////////
00099 INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl::
00100 get_ptr(const TVOLATILE AtomicAdjustDummyImpl::Pointer &var) {
00101   return var;
00102 }
00103 
00104 ////////////////////////////////////////////////////////////////////
00105 //     Function: AtomicAdjustDummyImpl::compare_and_exchange
00106 //       Access: Public, Static
00107 //  Description: Atomic compare and exchange.  
00108 //
00109 //               If mem is equal to old_value, store new_value in mem.
00110 //               In either case, return the original value of mem.
00111 //               The caller can test for success by comparing
00112 //               return_value == old_value.
00113 ////////////////////////////////////////////////////////////////////
00114 INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
00115 compare_and_exchange(TVOLATILE AtomicAdjustDummyImpl::Integer &mem, 
00116                      AtomicAdjustDummyImpl::Integer old_value,
00117                      AtomicAdjustDummyImpl::Integer new_value) {
00118   Integer orig_value = mem;
00119   if (mem == old_value) {
00120     mem = new_value;
00121   }
00122   return orig_value;
00123 }
00124 
00125 ////////////////////////////////////////////////////////////////////
00126 //     Function: AtomicAdjustDummyImpl::compare_and_exchange_ptr
00127 //       Access: Public, Static
00128 //  Description: Atomic compare and exchange.  
00129 //
00130 //               As above, but works on pointers instead of integers.
00131 ////////////////////////////////////////////////////////////////////
00132 INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl::
00133 compare_and_exchange_ptr(TVOLATILE AtomicAdjustDummyImpl::Pointer &mem, 
00134                          AtomicAdjustDummyImpl::Pointer old_value,
00135                          AtomicAdjustDummyImpl::Pointer new_value) {
00136   Pointer orig_value = mem;
00137   if (mem == old_value) {
00138     mem = new_value;
00139   }
00140   return orig_value;
00141 }
 All Classes Functions Variables Enumerations